/* Screen-specific layout. */

/* Auth -------------------------------------------------------------------- */

.auth-shell { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s5); min-height: 100vh; padding: var(--s5) var(--s4); }
.auth-card { width: 100%; max-width: 26rem; }
.auth-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-md); background: var(--accent); color: var(--accent-fg); }
.auth-mark svg { width: 24px; height: 24px; }

/* Document canvas.
   A proportional page surface. Field positions are normalised 0-1 against the
   page, so a marker sits in the same place at every width and zoom level. */

.doc-stage { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.doc-toolbar { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }

.page {
  position: relative;
  aspect-ratio: 1 / 1.294;           /* US Letter */
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-md);
  overflow: hidden;
  touch-action: manipulation;
}
.page.placing { cursor: crosshair; }
/* The rendered page is white regardless of theme — it is paper, not chrome. */
.page.has-render { background: #ffffff; }
.page-render { position: absolute; inset: 0; width: 100%; height: auto; display: block; }
.page-rules { position: absolute; inset: 8% 10%; display: flex; flex-direction: column; gap: 3.2%; pointer-events: none; }
.page-rules i { display: block; height: 6px; border-radius: 3px; background: var(--surface-3); }
.page-rules i:nth-child(4n) { width: 62%; }
.page-rules i:nth-child(5n) { width: 84%; }
.page-status {
  position: absolute; inset: auto 0 0 0;
  display: flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: var(--s2); pointer-events: none;
  color: var(--text-muted); font-size: var(--fs-xs);
}
.page.has-render .page-status:not(:empty) {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.page-watermark {
  position: absolute; inset: auto var(--s3) var(--s3) auto;
  color: var(--text-faint); font-size: var(--fs-xs); font-weight: 650;
  letter-spacing: 0.06em; text-transform: uppercase; pointer-events: none;
}

.fieldmark {
  position: absolute; box-sizing: border-box;
  display: flex; align-items: center; gap: var(--s1);
  min-height: 20px; padding: 1px var(--s2);
  border: 1.5px solid var(--accent); border-radius: var(--r-sm);
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 700; line-height: 1.1;
  overflow: hidden; text-align: left;
  transition: box-shadow var(--dur-fast) var(--ease);
}
.fieldmark span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fieldmark:hover, .fieldmark:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.fieldmark[data-selected="true"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }
.fieldmark.done { border-color: var(--success); background: var(--success-soft); color: var(--success); }
.fieldmark.todo { border-color: var(--warning); background: var(--warning-soft); color: var(--warning); }
/* Signer colour-coding is always paired with the signer's name in the label. */
.fieldmark.s1 { border-color: var(--sig1); background: var(--sig1-soft); color: var(--sig1); }
.fieldmark.s2 { border-color: var(--sig2); background: var(--sig2-soft); color: var(--sig2); }
.fieldmark.s3 { border-color: var(--sig3); background: var(--sig3-soft); color: var(--sig3); }
.fieldmark.s4 { border-color: var(--sig4); background: var(--sig4-soft); color: var(--sig4); }
.fieldmark.s5 { border-color: var(--sig5); background: var(--sig5-soft); color: var(--sig5); }
.fieldmark.s6 { border-color: var(--sig6); background: var(--sig6-soft); color: var(--sig6); }
.fieldmark.s7 { border-color: var(--sig7); background: var(--sig7-soft); color: var(--sig7); }
.fieldmark.s8 { border-color: var(--sig8); background: var(--sig8-soft); color: var(--sig8); }

/* Guided navigation lands here: a two-beat glow, neutralised by reduced-motion. */
.fieldmark.pulse { animation: mark-pulse 0.8s var(--ease) 2; }
@keyframes mark-pulse {
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 45%, transparent); }
}

/* A signed mark shows the signature itself, not a coloured box. */
.fieldmark-label { display: flex; align-items: center; justify-content: flex-start; width: 100%; height: 100%; overflow: hidden; }
.fieldmark-sig { max-width: 100%; max-height: 100%; object-fit: contain; }
.fieldmark-script { font-size: clamp(11px, 2.2cqw, 20px); color: #11201f; }
.fieldmark.done .fieldmark-script { color: var(--success); }

/* Alignment guides: appear while a dragged mark snaps to a neighbour's edge or centre. */
.snap-guide { position: absolute; background: var(--accent); opacity: 0.55; pointer-events: none; z-index: 3; }
.snap-guide.v { top: 0; bottom: 0; width: 1px; }
.snap-guide.h { left: 0; right: 0; height: 1px; }

/* Resize handles, shown while the mark is selected or hovered. */
.fm-handle { position: absolute; display: none; background: var(--accent); border-radius: var(--r-full); z-index: 2; }
.fieldmark[data-selected="true"] .fm-handle, .fieldmark:hover .fm-handle { display: block; }
.fm-handle.e  { right: -4px; top: 50%; width: 8px; height: 14px; margin-top: -7px; cursor: ew-resize; }
.fm-handle.s  { bottom: -4px; left: 50%; width: 14px; height: 8px; margin-left: -7px; cursor: ns-resize; }
.fm-handle.se { right: -5px; bottom: -5px; width: 11px; height: 11px; cursor: nwse-resize; }

.palette { display: flex; flex-wrap: wrap; gap: var(--s2); }
.palette button {
  padding: var(--s1) var(--s3); min-height: 32px;
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-xs); font-weight: 650;
}
.palette button:hover { border-color: var(--accent); color: var(--accent); }
.palette button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); font-size: var(--fs-xs); color: var(--text-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: var(--s1); border-radius: 3px; vertical-align: -1px; }
.legend-swatch.s1 { background: var(--sig1); } .legend-swatch.s2 { background: var(--sig2); }
.legend-swatch.s3 { background: var(--sig3); } .legend-swatch.s4 { background: var(--sig4); }
.legend-swatch.s5 { background: var(--sig5); } .legend-swatch.s6 { background: var(--sig6); }
.legend-swatch.s7 { background: var(--sig7); } .legend-swatch.s8 { background: var(--sig8); }

/* Continuous-scroll viewer -------------------------------------------------- */

.viewer-toolbar {
  position: sticky; top: calc(var(--header-h) + var(--s2)); z-index: 5;
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
}
.viewer-scroll { overflow-x: auto; }
.viewer-pages { display: flex; flex-direction: column; gap: var(--s4); margin: 0 auto; min-width: min(100%, 20rem); }
.viewer .page { container-type: inline-size; }

/* Signature pad ----------------------------------------------------------- */

/* Deliberately paper-coloured in both themes: the drawn signature is flattened
   onto white and embedded in the PDF, so the ink must be dark either way. */
.sigpad {
  width: 100%; aspect-ratio: 5 / 2; touch-action: none;
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-md);
  background: #fbfbfa; cursor: crosshair;
}
.sig-preview {
  display: grid; place-items: center; min-height: 84px; padding: var(--s3);
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2);
}
.sig-script { font-family: var(--font-display); font-size: var(--fs-xl); font-style: italic; letter-spacing: 0.01em; }
.sig-preview img { max-height: 72px; }

/* Signing ceremony -------------------------------------------------------- */

/* The document comes first at every width: it is the thing being signed. On a phone the field
   list follows below and the sticky bottom bar carries progress and the guided controls. */
.ceremony { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); align-items: start; }
@media (min-width: 68rem) {
  .ceremony { grid-template-columns: minmax(0, 1fr) 24rem; }
  .ceremony .ceremony-fields { position: sticky; top: calc(var(--header-h) + var(--s4)); max-height: calc(100vh - var(--header-h) - var(--s6)); overflow-y: auto; }
}

.ceremony-title { font-size: var(--fs-lg); }

/* The mobile action bar: progress, next field, finish — always in thumb's reach. */
.ceremony-bar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s4);
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow-lg);
}
.ceremony-wrap { padding-bottom: var(--s8); }
@media (min-width: 68rem) {
  .ceremony-bar { display: none; }
  .ceremony-wrap { padding-bottom: 0; }
}

.progress-track { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--r-full); background: var(--accent); transition: width var(--dur) var(--ease); }

.field-task { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3) var(--s4); border-top: 1px solid var(--border); }
.field-task:first-child { border-top: 0; }

/* Quick sign lays the same row out horizontally: label, status, locate, action. The base rule
   stacks, because the signing ceremony passes exactly two block children. */
.field-task.row { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.field-task.row > .task-locate { flex: 1 1 auto; }
.field-task[data-state="todo"] { background: var(--surface); }
.field-task[data-state="done"] { background: var(--surface-2); }

/* The row header doubles as "show me this field on the page". */
.task-locate {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  padding: 0; border: 0; background: transparent; color: inherit;
  text-align: left; cursor: pointer; min-width: 0;
}
.task-locate:hover .strong { color: var(--accent); }

/* Per-field save confirmation: appears on save, fades out on its own. */
.save-note { color: var(--success); font-size: var(--fs-xs); font-weight: 650; opacity: 0; transition: opacity var(--dur) var(--ease); }
.save-note.shown { opacity: 1; }

/* Task groups per document in the rail. */
.doc-group { border-top: 1px solid var(--border); }
.doc-group:first-child { border-top: 0; }
.doc-group-head {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  padding: var(--s2) var(--s4);
  border: 0; background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 700; text-align: left;
}
.doc-group-head:hover { color: var(--text); }
.doc-group-head[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

.sig-preview.slim { min-height: 44px; flex: 1 1 auto; padding: var(--s1) var(--s2); }
.sig-preview.slim .sig-script { font-size: var(--fs-md); }

/* Verification record ----------------------------------------------------- */

.verdict {
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s5);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface);
}
.verdict.ok   { border-color: var(--success-line); background: var(--success-soft); }
.verdict.bad  { border-color: var(--danger-line);  background: var(--danger-soft); }
.verdict.warn { border-color: var(--warning-line); background: var(--warning-soft); }
.verdict-icon { display: grid; place-items: center; width: 48px; height: 48px; flex: none; border-radius: var(--r-full); background: var(--surface); }
.verdict-icon svg { width: 26px; height: 26px; }
.verdict.ok .verdict-icon { color: var(--success); }
.verdict.bad .verdict-icon { color: var(--danger); }
.verdict.warn .verdict-icon { color: var(--warning); }
.verdict h2 { font-size: var(--fs-lg); }
.verdict p { font-size: var(--fs-sm); color: var(--text-muted); }
.verdict.ok p, .verdict.bad p, .verdict.warn p { color: inherit; opacity: 0.85; }

.check-row { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.check-row:first-child { border-top: 0; }
.check-row svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.check-row.ok svg { color: var(--success); }
.check-row.bad svg { color: var(--danger); }
.check-row.warn svg { color: var(--warning); }
.check-row .check-body { min-width: 0; }

/* Admin ------------------------------------------------------------------- */

.admin-nav { display: flex; gap: var(--s1); overflow-x: auto; padding-bottom: var(--s1); scrollbar-width: none; }
.admin-nav::-webkit-scrollbar { display: none; }
.admin-nav a {
  flex: none; padding: var(--s2) var(--s3); border-radius: var(--r-md);
  color: var(--text-muted); font-size: var(--fs-sm); font-weight: 650;
  text-decoration: none; white-space: nowrap;
}
.admin-nav a:hover { background: var(--surface-2); color: var(--text); }
.admin-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.meter { display: flex; height: 8px; border-radius: var(--r-full); overflow: hidden; background: var(--surface-3); }
.meter i { display: block; height: 100%; }
.meter i.ok { background: var(--success); }
.meter i.warn { background: var(--warning); }
.meter i.bad { background: var(--danger); }
.meter i.accent { background: var(--accent); }
.meter i.plain { background: var(--border-strong); }


/* Adding a document: upload, write, or start from a template ---------------- */

.source-options { display: grid; grid-template-columns: 1fr; gap: var(--s3); }
@media (min-width: 62rem) { .source-options { grid-template-columns: repeat(3, 1fr); } }
.source-option { display: flex; min-width: 0; }
.source-option .filedrop { flex: 1 1 auto; }
.source-action {
  flex: 1 1 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: var(--s2);
  padding: var(--s6) var(--s4); text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface-2); color: var(--text-muted);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.source-action:hover { border-color: var(--accent); background: var(--accent-soft); }
.source-action svg { width: 26px; height: 26px; color: var(--text-faint); }

.upload-row { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.upload-row.ok .progress-fill { background: var(--success); }
.upload-row.bad .progress-fill { background: var(--danger); }

.reorder { display: flex; flex-direction: column; gap: 0; }

/* Document editor ----------------------------------------------------------- */

.editor-toggle { display: none; margin: var(--s4) 0 0; align-self: flex-start; }

.editor-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); align-items: start; margin-top: var(--s4); }
@media (min-width: 62rem) {
  .editor-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .editor-split .preview-pane { position: sticky; top: calc(var(--header-h) + var(--s4)); max-height: calc(100vh - var(--header-h) - var(--s6)); overflow-y: auto; }
}
@media (max-width: 61.99rem) {
  .editor-toggle { display: flex; }
  .editor-split[data-pane="edit"] .preview-pane { display: none; }
  .editor-split[data-pane="preview"] .editor-pane { display: none; }
}

.block-editor { display: flex; flex-direction: column; }
.blocks { display: flex; flex-direction: column; }
.block {
  position: relative;
  padding: var(--s3) var(--s4) 0;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
  margin-bottom: 0;
}
.block:focus-within { border-color: var(--accent-line); }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.block-kind { color: var(--text-faint); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.block-tools { display: flex; gap: 2px; opacity: 0.35; transition: opacity var(--dur-fast) var(--ease); }
.block:hover .block-tools, .block:focus-within .block-tools { opacity: 1; }

.block-text {
  width: 100%; padding: var(--s1) 0; border: 0; background: transparent; color: var(--text);
  font-size: var(--fs-base); line-height: 1.5; resize: none; overflow: hidden;
}
.block-text:focus { outline: none; }
.block-text.h1 { font-size: var(--fs-xl); font-weight: 700; }
.block-text.h2 { font-size: var(--fs-lg); font-weight: 700; }
.block-text.h3 { font-size: var(--fs-md); font-weight: 650; }
.block-heading .block-text { font-weight: 700; }

.block-add-row { position: relative; display: flex; flex-direction: column; align-items: center; padding: var(--s1) 0; }
.block-add {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: 2px var(--s2); border: 0; border-radius: var(--r-full);
  background: transparent; color: var(--text-faint); font-size: var(--fs-xs); font-weight: 650;
  opacity: 0.5; transition: opacity var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.block-add:hover { opacity: 1; color: var(--accent); }
.block-menu {
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s1);
  padding: var(--s2); margin-top: var(--s1);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-md);
}
.block-menu button {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: var(--s1) var(--s3); border: 1px solid var(--border-strong); border-radius: var(--r-full);
  background: var(--surface); color: var(--text); font-size: var(--fs-xs); font-weight: 650;
}
.block-menu button:hover { border-color: var(--accent); color: var(--accent); }

.block-table table { border-collapse: collapse; }
.block-table td { padding: 2px; }
.block-table tr.head input { font-weight: 700; }
.block-table td.row-remove { width: 34px; }
.list-marker { width: 18px; flex: none; text-align: right; }

.sig-block { border-top: 1px dashed var(--border); padding-top: var(--s3); }

/* Quick sign -------------------------------------------------------------
   Place fields on a PDF and sign it in the same sitting. Reuses the page,
   field-mark, palette and viewer rules above; only the signature rail and the
   phone bar are new. */

.sigtile {
  display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: var(--s3);
  align-items: center; width: 100%; padding: var(--s2); text-align: left;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.sigtile:hover { border-color: var(--accent-line); }
.sigtile[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.sigtile.compact { grid-template-columns: 52px minmax(0, 1fr); }
.sigtile-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* Paper, not chrome: a stored signature PNG is flattened onto white, so a dark
   surface behind it would show a white rectangle. Same reasoning as
   .page.has-render and .sigpad above. */
.sigtile-thumb {
  display: grid; place-items: center; height: 44px; padding: 2px;
  border-radius: var(--r-sm); background: #ffffff; overflow: hidden;
}
.sigtile-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sigtile-thumb .sig-script { color: #11201f; font-size: var(--fs-sm); }

.sigrail-list { display: flex; flex-direction: column; gap: var(--s2); max-height: 18rem; overflow-y: auto; }

/* The phone action bar. Deliberately a copy of .ceremony-bar rather than a
   shared class: the ceremony is the highest-stakes screen in the product and is
   not worth touching for this. A later refactor can fold both into one. */
.quick-bar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s4);
  padding-bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow-lg);
}
.quick-bar .sigtile-thumb { height: 32px; width: 48px; }
.quick-wrap { padding-bottom: var(--s8); }
@media (min-width: 68rem) {
  .quick-bar { display: none; }
  .quick-wrap { padding-bottom: 0; }
}

/* Two ways in, rather than the three the envelope screen offers. */
@media (min-width: 62rem) { .source-options.pair { grid-template-columns: repeat(2, 1fr); } }
