/* =========================================================================
   The page a patient opens from an email: a document to read, and sometimes
   to sign.

   Layered on top of form.css, which already sets the palette, the type and
   the one-column shape. What is added here is the document itself — which has
   to look like a document, not like a web page — and the signature panel.
   ========================================================================= */

.doc-sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 30px 30px 34px;
  margin-bottom: 22px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  overflow-wrap: break-word;
}
@media (max-width: 640px) { .doc-sheet { padding: 20px 18px 24px; font-size: 14.5px; } }

/* ---- ink: a signature and a stamp on a document -----------------------
 *
 * Blue, on purpose. A printed document in blue pen is visibly an original
 * rather than a photocopy of one, which is the whole reason a practice signs
 * in blue and stamps in blue.
 *
 * The stamp sits opposite the signature on the same line, the way a rubber
 * stamp lands beside a pen rather than under it, and the block is kept
 * together when the page breaks — a signature alone at the top of page three
 * is a mark on a page, not a signed document.
 */
.doc-sign { margin-top: 26px; break-inside: avoid; page-break-inside: avoid; }
.doc-sign-marks {
  display: flex; align-items: flex-end; justify-content: flex-start;
  gap: 22px; min-height: 46px;
}
.doc-sign .ink-sig { width: 132px; height: auto; }
.doc-sign .ink-stamp { width: 178px; height: auto; }
.doc-sign .ink-rule { flex: 0 0 220px; border-bottom: 1px solid var(--ink-3, #7b827f); height: 34px; }
.doc-sign-who { font-size: .76rem; color: var(--ink-3, #7b827f); margin-top: 4px; line-height: 1.45; }

/* ---- the two spaces at the foot of a consent form ----------------------
 *
 * One for the patient and one for the surgeon, side by side where there is
 * room and stacked where there is not. Each is a mark over a ruled line with
 * a name and a date under it — which is what the typed underscores they
 * replaced were always trying to be.
 *
 * The rule is drawn under the marks rather than instead of them, so a signed
 * space and an unsigned one are the same shape and a form printed for signing
 * by hand still has somewhere to sign.
 */
.doc-sig-slot {
  display: inline-block; vertical-align: top;
  width: 46%; min-width: 220px; margin: 26px 3% 0 0;
  break-inside: avoid; page-break-inside: avoid;
}
.doc-sig-slot .doc-sign-marks {
  justify-content: flex-start; gap: 14px; min-height: 54px;
  border-bottom: 1px solid var(--ink-3, #7b827f); padding-bottom: 2px;
}
.doc-sig-slot .ink-sig { width: auto; max-width: 160px; max-height: 54px; }
.doc-sig-slot .ink-stamp { width: auto; max-width: 140px; max-height: 54px; }
.doc-sig-rule { display: block; width: 100%; height: 44px; }
.doc-sig-typed {
  font-family: "Snell Roundhand", "Apple Chancery", "Segoe Script", "Bradley Hand", cursive;
  font-size: 1.5rem; line-height: 1; color: #152238; align-self: flex-end; padding-bottom: 4px;
}
.doc-sig-when { font-weight: 600; }
.doc-sig-how { opacity: .8; }
@media (max-width: 560px) {
  .doc-sig-slot { width: 100%; margin-right: 0; }
  .doc-sig-slot .doc-sign-marks { flex-direction: row; align-items: flex-end; gap: 14px; }
}

@media (max-width: 560px) {
  .doc-sign-marks { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* ---- an information leaflet, read page by page ------------------------
 *
 * `aspect-ratio` is not decoration. Until an image has loaded it is nought
 * pixels tall, so without it a three-page leaflet measures as a short
 * document and the "you have reached the end" check opens the signature panel
 * before page one has appeared. Reserving A4 keeps the page the right height
 * from the first frame, and stops the text jumping about as each page lands.
 */
.leaflet-pages { margin: 0 0 22px; display: grid; gap: 14px; }
.leaflet-page {
  display: block; width: 100%; aspect-ratio: 1 / 1.414;
  /* The ratio is kept after loading as well as before it, so the reserved
     height never changes; `contain` is what stops a sheet that is not A4 from
     being stretched to fit it. Letterboxed is honest, distorted is not. */
  object-fit: contain;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px;
}
@media print { .leaflet-page { break-inside: avoid; border: 0; } }

/* A document of photographs. The same reservation as a leaflet page and for
   the same reason — an image with no height yet makes the page measure short
   — but in the proportion a camera actually produces. */
.doc-photos {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px; margin: 18px 0 22px;
}
.doc-photo-fig { margin: 0; break-inside: avoid; }
.doc-photo {
  display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
}
.doc-photo-fig figcaption { font-size: .82rem; opacity: .75; margin-top: 6px; }
@media print { .doc-photo { break-inside: avoid; border: 0; } }

.doc-sheet h1, .doc-sheet h2, .doc-sheet h3, .doc-sheet h4 {
  line-height: 1.3; margin: 22px 0 8px; font-weight: 650;
}
.doc-sheet h2 { font-size: 1.05rem; }
.doc-sheet h3 { font-size: .95rem; }
.doc-sheet h4 { font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.doc-sheet p { margin: 0 0 10px; }
.doc-sheet ul, .doc-sheet ol { margin: 0 0 12px; padding-left: 22px; }
.doc-sheet li { margin-bottom: 5px; }
.doc-sheet hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.doc-sheet .muted { color: var(--ink-3); font-size: .88em; }
.doc-sheet .small { font-size: .88em; }
.doc-sheet .lead { font-size: 1.05rem; margin: 18px 0; }

.doc-sheet .doc-head {
  display: flex; justify-content: space-between; gap: 24px; align-items: flex-start;
  border-bottom: 2px solid var(--ink); padding-bottom: 16px; margin-bottom: 20px;
}
.doc-sheet .doc-head .clinic b { font-size: 1.05rem; display: block; margin-bottom: 2px; }
.doc-sheet .clinic-logo { display: block; height: auto; width: auto; max-height: 108px; max-width: 390px; margin: 0 0 12px; }
.doc-sheet .doc-head .clinic span { display: block; font-size: .82rem; color: var(--ink-3); }
.doc-sheet .doc-head .meta { text-align: right; font-size: .82rem; color: var(--ink-3); white-space: nowrap; }
.doc-sheet .doc-head .meta b {
  display: block; font-size: 1.05rem; color: var(--ink); letter-spacing: .04em; margin-bottom: 2px;
}
@media (max-width: 560px) {
  .doc-sheet .doc-head { flex-direction: column; gap: 12px; }
  .doc-sheet .doc-head .meta { text-align: left; }
}

.doc-sheet .doc-parties { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 20px; }
.doc-sheet .party h4 { margin: 0 0 3px; }
.doc-sheet .party b { display: block; }
.doc-sheet .party span { display: block; font-size: .85rem; color: var(--ink-3); }

.doc-sheet table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: .92em; }
.doc-sheet th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); font-weight: 650; padding: 7px 8px; border-bottom: 1px solid var(--line);
}
.doc-sheet td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc-sheet .right { text-align: right; }

.doc-sheet .doc-kv { margin: 8px 0 14px; }
.doc-sheet .doc-kv > div { display: flex; gap: 14px; padding: 3px 0; align-items: baseline; }
.doc-sheet .doc-kv > div > span:first-child { flex: 0 0 150px; color: var(--ink-3); }
.doc-sheet .doc-kv > div > span:last-child { flex: 1; min-width: 0; }
.doc-sheet .doc-totals { margin-left: auto; width: min(300px, 100%); margin-top: 14px; }
.doc-sheet .doc-totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.doc-sheet .doc-totals .grand {
  border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 9px;
  font-size: 1.05rem; font-weight: 700;
}
.doc-sheet .doc-foot {
  margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: .78rem; color: var(--ink-3);
}

/* ------------------------------------------------------ signature panel */

.sign-panel {
  background: var(--surface); border: 1px solid var(--accent-line);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
  padding: 24px 26px; margin-bottom: 24px;
}
@media (max-width: 640px) { .sign-panel { padding: 20px 18px; } }
.sign-panel h2 { font-size: 1.1rem; margin: 0 0 6px; }
.sign-panel .statement {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; font-size: .92rem; line-height: 1.6; color: var(--ink-2); margin: 14px 0 18px;
}

.sign-tabs { display: flex; gap: 2px; margin-bottom: 14px; }
.sign-tabs button {
  flex: 1; padding: 9px 12px; border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-2); font: inherit; font-size: .88rem; font-weight: 550; cursor: pointer;
}
.sign-tabs button:first-child { border-radius: 9px 0 0 9px; }
.sign-tabs button:last-child { border-radius: 0 9px 9px 0; border-left: 0; }
.sign-tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.sign-pad-wrap { position: relative; }
.sign-pad {
  width: 100%; height: 190px; display: block; touch-action: none; cursor: crosshair;
  background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 10px;
}
.sign-pad-hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--ink-3); font-size: .88rem; pointer-events: none;
}
.sign-pad-clear { margin-top: 8px; }

.typed-preview {
  font-family: var(--serif); font-size: 1.7rem; font-style: italic;
  padding: 16px 4px 10px; border-bottom: 1px solid var(--line-strong);
  min-height: 62px; color: var(--ink); word-break: break-word;
}

.sign-done {
  background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 32%, transparent);
  border-radius: var(--radius); padding: 26px 24px; text-align: center; margin-bottom: 22px;
}
.sign-done .tick {
  width: 46px; height: 46px; border-radius: 50%; background: var(--ok); color: #fff;
  display: grid; place-items: center; margin: 0 auto 12px; font-size: 24px;
}
.sign-done h2 { margin: 0 0 6px; font-size: 1.15rem; }
.sign-done p { margin: 0; color: var(--ink-2); font-size: .92rem; }

.sign-legal {
  font-size: .76rem; color: var(--ink-3); line-height: 1.6; margin-top: 16px;
}

.doc-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 26px; }
/* form.css makes every button full width; a secondary action here should not be. */
.btn.auto { width: auto; padding: 10px 18px; font-size: 14.5px; }

.masthead .sub { margin: 8px 0 0; color: var(--ink-3); font-size: 14.5px; }
.sign-done .signed-at { margin-top: 8px; font-size: .85rem; color: var(--ink-3); }
#sign-root { min-height: 100vh; }

/* Pressing Print uses a clean frame — see client/js/printsheet.js — so what
   comes out is the A4 sheet and nothing else. This is for the browser's own
   Ctrl+P, which prints the page as it stands: the masthead goes too, because
   the practice's name in a heading above the practice's name in the
   letterhead is not a document, it is a screenshot of one. */
@media print {
  @page { size: A4; margin: 14mm 15mm; }
  .masthead, .sign-panel, .doc-actions, .page-foot, .sign-legal, .footnote,
  .sign-done, .btn { display: none !important; }
  .doc-sheet { box-shadow: none; border: 0; padding: 0; margin: 0; max-width: none; }
  body, .shell, #sign-root { background: #fff; margin: 0; padding: 0; max-width: none; }
}

/* The practice's logo above its name, when one has been set. */
.masthead-logo { display: block; height: auto; width: auto; max-height: 52px; max-width: 220px; margin: 0 0 10px; }

/* Who is signing: shown from the record, confirmed with a tick, never typed. */
.sign-who .sign-identity { font-size: 1.05rem; margin: 4px 0 2px; }
.sign-who .sign-identity .muted { color: var(--ink-3); font-size: .92rem; font-weight: 400; }
.sign-identity-why { margin: 2px 0 12px; font-size: .84rem; line-height: 1.5; }
