/* ==========================================================================
   Formulary Manager — client portal
   --------------------------------------------------------------------------
   Loads AFTER app.css and inherits every token. The portal is the same
   design language at a calmer density: no ink sidebar, a single centred
   column, larger type, more air. A provider visits a few times a year to
   read their pricing and sign a document — nothing here should feel like
   an operator's console.
   ========================================================================== */

.portal {
  --topbar-h: 64px;
  background: var(--n-25);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* -- Masthead: a hairline rule bar, client name set as the subject -------- */
.pmast {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.pmast__inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 var(--s-6);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.pmast__brand { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.pmast__mark {
  width: 28px; height: 28px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--vd-200);
  border-radius: var(--r-1);
  background: var(--vd-50);
  color: var(--vd-600);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
}
.pmast__name { font-size: 15px; font-weight: 600; letter-spacing: -.008em; line-height: 1.2; }
.pmast__client {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.pmast__spacer { flex: 1 1 auto; }

/* -- Portal navigation: text only, verdigris underline on the active tab -- */
.pnav { display: flex; gap: var(--s-1); }

/* The duplicate nav strip under the masthead is for narrow screens only.
   It inherits display:flex from .pnav, so it has to be switched off here or
   it shows on desktop as a second row of tabs. */
.pnav--mobile { display: none; }
.pnav__item {
  position: relative;
  padding: var(--s-2) var(--s-3);
  border: 0;
  border-radius: var(--r-2);
  background: none;
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.pnav__item:hover { color: var(--fg); background: var(--n-50); text-decoration: none; }
.pnav__item.is-active { color: var(--vd-600); background: var(--vd-50); }

/* -- Body: one centred column, generous rhythm ---------------------------- */
.pbody {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--s-10) var(--s-6) var(--s-16);
}
.pbody--narrow { max-width: 680px; }

.phead { margin-bottom: var(--s-8); }
.phead__eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin-bottom: var(--s-2);
}
.phead__title { font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; }
.phead__text { margin-top: var(--s-3); font-size: 15.5px; color: var(--fg-muted); max-width: 62ch; line-height: 1.6; }

.psection + .psection { margin-top: var(--s-12); }

.psection__head {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  padding-bottom: var(--s-3);
  margin-bottom: var(--s-5);
  border-bottom: 1px solid var(--rule);
}
.psection__title { font-size: 17px; font-weight: 600; letter-spacing: -.008em; }
.psection__count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
}
.psection__head .btnrow { margin-left: auto; }

/* -- The portal's formulary sheet: same rules, roomier rows --------------- */
.portal .sheet { font-size: 14.5px; }
.portal .sheet thead th { background: var(--n-25); padding: var(--s-3); }
.portal .sheet tbody td { padding: var(--s-4) var(--s-3); }
.portal .sheet tbody tr:hover { background: transparent; }

.portal .panel { box-shadow: none; }

/* -- Document rows: a signed contract reads as a filed record ------------- */
.docrow {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--rule-soft);
}
.docrow:last-child { border-bottom: 0; }

.docrow__glyph {
  width: 38px; height: 46px;
  flex: none;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-1);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--fg-subtle);
  position: relative;
}
/* A folded corner — the page as object. */
.docrow__glyph::after {
  content: "";
  position: absolute;
  top: -1px; right: -1px;
  width: 11px; height: 11px;
  background: var(--n-25);
  border-left: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
}
.docrow__body { flex: 1 1 auto; min-width: 0; }
.docrow__title { font-weight: 500; font-size: 15px; letter-spacing: -.004em; }
.docrow__meta {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.docrow__meta .mono { font-size: 12px; }

/* -- Action card: the one thing the provider is here to do --------------- */
.callout {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-5);
  border: 1px solid var(--amber-200);
  border-left-width: 2px;
  border-radius: var(--r-3);
  background: var(--amber-50);
}
.callout__body { flex: 1 1 auto; min-width: 0; }
.callout__title { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.callout__text { font-size: 13.5px; color: var(--amber-700); }

@media (max-width: 640px) {
  .pbody { padding: var(--s-6) var(--s-4) var(--s-12); }
  .pmast__inner { padding: 0 var(--s-4); }
  .phead__title { font-size: 25px; }
  .callout { flex-direction: column; align-items: stretch; }
  .pnav { display: none; }
  .pnav--mobile {
    display: flex;
    overflow-x: auto;
    gap: var(--s-1);
    padding: var(--s-2) var(--s-4);
    border-top: 1px solid var(--rule-soft);
    scrollbar-width: none;
  }
  .pnav--mobile::-webkit-scrollbar { display: none; }
}

/* ==========================================================================
   Signing ceremony — used by both the portal and the emailed signing link
   ========================================================================== */
.sign {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--n-100);
}

.sign__bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-5);
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.sign__bar .grow { min-width: 0; }
.sign__title { font-size: 14px; font-weight: 600; letter-spacing: -.006em; }
.sign__meta { font-size: 12px; color: var(--fg-muted); }

/* Progress through the required fields, as a count not a bar. */
.sign__progress {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
  white-space: nowrap;
}

.sign__stage {
  flex: 1 1 auto;
  overflow: auto;
  padding: var(--s-6) var(--s-4) var(--s-16);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-5);
}

/* Each PDF page is a sheet of paper with a hairline edge. */
.pdfpage {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--rule);
}
.pdfpage canvas { display: block; }

.pdfpage__no {
  position: absolute;
  left: 0; right: 0; bottom: -22px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
}

/* -- Field markers laid over the page ------------------------------------ */
.fieldbox {
  position: absolute;
  border: 1px solid var(--vd-500);
  border-radius: var(--r-1);
  background: rgba(28, 110, 102, .07);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.fieldbox:hover { background: rgba(28, 110, 102, .13); }
.fieldbox__label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--vd-600);
  pointer-events: none;
  padding: 0 4px;
  text-align: center;
}
.fieldbox.is-required { border-style: solid; }
.fieldbox.is-optional { border-style: dashed; }
.fieldbox.is-filled {
  border-color: var(--seal-600);
  background: rgba(29, 107, 66, .05);
}
.fieldbox.is-filled .fieldbox__label { display: none; }
.fieldbox.is-next {
  border-color: var(--amber-600);
  background: rgba(138, 90, 18, .1);
  box-shadow: 0 0 0 3px rgba(138, 90, 18, .14);
}
.fieldbox.is-next .fieldbox__label { color: var(--amber-700); }

.fieldbox__ink { max-width: 100%; max-height: 100%; }
.fieldbox__text {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--n-900);
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
}
.fieldbox__script {
  font-family: "Pinyon Script", "Segoe Script", cursive;
  font-size: 26px;
  line-height: 1;
  color: #10243a;
  white-space: nowrap;
  overflow: hidden;
}

/* -- Signature pad ------------------------------------------------------- */
.pad {
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-2);
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
.pad canvas { display: block; width: 100%; height: 160px; touch-action: none; cursor: crosshair; }
/* The signature line, printed on the pad like a form. */
.pad::after {
  content: "";
  position: absolute;
  left: 16px; right: 16px;
  bottom: 42px;
  border-bottom: 1px solid var(--rule);
  pointer-events: none;
}
.pad__hint {
  position: absolute;
  left: 16px;
  bottom: 48px;
  font-size: 12px;
  color: var(--fg-subtle);
  pointer-events: none;
}
.pad.has-ink .pad__hint { display: none; }

.typedsig {
  display: grid;
  place-items: center;
  min-height: 92px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-2);
  background: var(--surface);
  font-family: "Pinyon Script", "Segoe Script", cursive;
  font-size: 38px;
  color: #10243a;
  padding: var(--s-4);
  text-align: center;
  word-break: break-word;
}
.typedsig.is-empty { color: var(--fg-subtle); font-family: var(--sans); font-size: 14px; }

/* -- The consent block: plain language, never buried --------------------- */
.consent {
  padding: var(--s-4);
  border: 1px solid var(--rule);
  border-radius: var(--r-2);
  background: var(--surface-sunk);
  font-size: 13px;
  line-height: 1.55;
  color: var(--n-700);
}

/* -- Completion ---------------------------------------------------------- */
.done {
  max-width: 460px;
  margin: var(--s-16) auto;
  text-align: center;
}
.done__seal {
  width: 76px; height: 76px;
  margin: 0 auto var(--s-6);
  border: 2px solid var(--seal-600);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--seal-600);
}
.done__seal svg { width: 34px; height: 34px; }

@media (max-width: 720px) {
  .sign__stage { padding: var(--s-4) var(--s-2) var(--s-12); }
  .sign__bar { flex-wrap: wrap; gap: var(--s-2); padding: var(--s-2) var(--s-4); }
}

/* ==========================================================================
   Print — the provider clicking "Print" on their formulary
   --------------------------------------------------------------------------
   Fixed-position overlays are appended to <body>, not inside the markup
   being printed, so they tile across every page or clip the content if left
   visible. Hide them explicitly rather than hoping they fall outside the
   print box.
   ========================================================================== */
@media print {
  .toasts, .scrim, .pmast, .pnav, .btnrow, .btn,
  .navscrim, .sidebar, .topbar { display: none !important; }

  html, body { background: #fff !important; }

  .portal { background: #fff; }

  .pbody {
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .phead { margin-bottom: 18pt; }
  .phead__title { font-size: 20pt; }
  .phead__text { font-size: 10pt; max-width: none; }

  .psection + .psection { margin-top: 20pt; }
  .psection__head { border-bottom: 1px solid #999; }
  .psection__title { font-size: 12pt; }

  .panel {
    border: 0 !important;
    box-shadow: none !important;
    break-inside: auto;
  }
  .panel__body, .panel__body--flush { padding: 0 !important; }

  .sheet { font-size: 9pt; }
  .sheet thead { display: table-header-group; }   /* repeat heads per page */
  .sheet thead th {
    position: static;
    background: #fff !important;
    border-bottom: 1px solid #333;
    padding: 4pt 6pt;
  }
  .sheet tbody tr { break-inside: avoid; }
  .sheet tbody td {
    padding: 5pt 6pt;
    border-bottom: 1px solid #ccc;
  }

  .stamp { border-color: #666 !important; background: none !important; color: #333 !important; }
  .callout, .notice { border: 1px solid #999; background: none !important; }

  a[href]::after { content: ""; }  /* no URL noise beside every link */

  @page { margin: 16mm 14mm; }
}
