/* ============================================================================
   Charter — Generated Handbook Document
   Styles the "paper" that renders in the preview pane, and the print/PDF output.
   ========================================================================== */

.doc {
  --pad: 64px;
  width: min(820px, calc(100% - 56px));
  margin: 0 auto;
  font-family: var(--font-doc);
  color: #1b2a22;
  counter-reset: sec;
}

/* a single paper page */
.page {
  background: var(--cream);
  border: 1px solid rgba(21,35,27,.10);
  border-radius: 3px;
  box-shadow: var(--shadow-doc);
  padding: var(--pad);
  margin-bottom: 26px;
  position: relative;
}
.page::after { /* subtle page edge */
  content: ""; position: absolute; inset: 0; border-radius: 3px; pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
}

/* ---- cover ---- */
.cover { min-height: 560px; display: flex; flex-direction: column; }
.cover .cv-top { display: flex; align-items: center; gap: .6rem; }
.cover .cv-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--emerald); color: var(--cream); display: grid; place-items: center; font-family: var(--font-display); font-size: 1.4rem; overflow: hidden; }
.cover .cv-mark .cs-cube { width: 80%; height: 80%; display: block; }
.cover .cv-brand { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; }
.cover .cv-center { margin: auto 0; }
.cover .cv-kicker { font-family: var(--font-ui); font-size: .8rem; letter-spacing: .26em; text-transform: uppercase; color: var(--ochre-600); font-weight: 700; }
.cover h1.cv-co { font-family: var(--font-display); font-weight: 600; font-size: clamp(2.4rem, 5vw, 3.6rem); line-height: 1.02; letter-spacing: -.02em; margin: .5rem 0 .3rem; color: var(--emerald-900); }
.cover .cv-title { font-family: var(--font-display); font-style: italic; font-weight: 500; font-size: 1.7rem; color: var(--ink-2); }
.cover .cv-rule { height: 2px; background: linear-gradient(90deg, var(--emerald), var(--ochre) 70%, transparent); width: 180px; margin: 1.4rem 0; }
.cover .cv-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: flex-end; font-family: var(--font-ui); font-size: .82rem; color: var(--ink-soft); }
.cover .cv-foot .ef { font-weight: 600; color: var(--ink-2); }
.cover .cv-draft {
  font-family: var(--font-ui); font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ochre-600); border: 1px solid var(--ochre-300); border-radius: 999px; padding: .3em .8em;
}

/* ---- table of contents ---- */
.toc h2 { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; margin-bottom: 1.2rem; color: var(--emerald-900); }
.toc-sec { margin-bottom: 1.2rem; }
.toc-sec .ts-head { display: flex; align-items: baseline; gap: .6rem; font-family: var(--font-ui); font-weight: 700; font-size: .98rem; color: var(--emerald-700); letter-spacing: .02em; padding-bottom: .3rem; border-bottom: 1px solid var(--line); margin-bottom: .4rem; }
.toc-sec .ts-num { color: var(--ochre-600); }
.toc-row { display: flex; align-items: baseline; gap: .5rem; font-family: var(--font-ui); font-size: .9rem; color: var(--ink-2); padding: .18rem 0; }
.toc-row .tr-num { flex: 0 0 auto; width: 2.6em; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.toc-row .tr-dots { flex: 1 1 auto; border-bottom: 1px dotted var(--line-2); transform: translateY(-.28em); }
.toc-row .tr-st { flex: 0 0 auto; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ochre-600); }

/* ---- body sections ---- */
.sec { counter-increment: sec; counter-reset: pol; margin-bottom: 30px; }
.sec-title {
  font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; color: var(--emerald-900);
  letter-spacing: -.01em; padding-bottom: .4rem; margin-bottom: 1rem;
  border-bottom: 2px solid var(--emerald);
  display: flex; align-items: baseline; gap: .6rem;
}
.sec-title .st-n { font-size: 1.1rem; color: var(--ochre-600); font-weight: 600; }

.pol { margin-bottom: 1.5rem; scroll-margin-top: 70px; }
.pol-h {
  font-family: var(--font-ui); font-weight: 700; font-size: 1.02rem; color: var(--ink);
  margin-bottom: .5rem; display: flex; align-items: baseline; gap: .5rem;
}
.pol-h .ph-n { color: var(--emerald); font-variant-numeric: tabular-nums; font-weight: 700; }
.pol-h .ph-state {
  font-size: .64rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ochre-600); border: 1px solid var(--ochre-300); border-radius: 4px; padding: .05em .45em;
  transform: translateY(-.1em);
}
.pol-body { font-size: .96rem; line-height: 1.62; color: #233029; }
.pol-body p { margin: 0 0 .7em; }
.pol-body strong { color: var(--ink); font-weight: 700; }
.pol-body em { color: var(--ink-soft); }
.pol-body ul { margin: .2em 0 .8em; padding-left: 1.3em; }
.pol-body li { margin-bottom: .3em; }
.pol-body li::marker { color: var(--ochre); }

/* scaffold / pending state note */
.scaffold-note {
  background: var(--ochre-100); border: 1px dashed var(--ochre-300); border-radius: var(--r-md);
  padding: .9em 1em; font-size: .9rem; color: var(--ochre-600); margin-bottom: 1rem;
}
.scaffold-note b { color: var(--ochre-600); }

/* highlight pulse when a token updates */
.tok { transition: background-color .1s; border-radius: 3px; padding: 0 .04em; }
.tok.pulse { background: var(--ochre-300); animation: tokfade 1.1s var(--ease) forwards; }
@keyframes tokfade { 0%{ background: var(--ochre-300);} 100%{ background: transparent; } }
.tok.empty { background: rgba(190,118,21,.14); color: var(--ochre-600); border-bottom: 1.5px dotted var(--ochre); font-style: italic; }

.page-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line);
  font-family: var(--font-ui); font-size: .72rem; color: var(--ink-faint);
}

/* custom free-text section preserves the author's line breaks */
.pol-body.prewrap { white-space: pre-wrap; }

/* ---- inline policy editing (unlocked handbooks) ---- */
.pol-body[contenteditable="true"] { position: relative; cursor: text; border-radius: 4px; }
.pol-body[contenteditable="true"]:hover { outline: 1.5px dashed var(--ochre-300); outline-offset: 8px; }
.pol-body[contenteditable="true"]:focus {
  outline: 1.5px solid var(--emerald); outline-offset: 8px;
  background: rgba(28,75,57,.03);
}
.pol-body[contenteditable="true"]:hover::after {
  content: "✎ Click to edit"; position: absolute; top: -1.9em; right: 0;
  font-family: var(--font-ui); font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  color: var(--ochre-600); background: var(--ochre-100); border: 1px solid var(--ochre-300);
  border-radius: 4px; padding: .15em .55em; pointer-events: none;
}
.pol-body[contenteditable="true"]:focus::after { display: none; }
.pol-body[contenteditable="true"]:empty { min-height: 1.5em; }
.pol-body[contenteditable="true"] .tok { cursor: default; }
.pol-h .pol-edited {
  font-family: var(--font-ui); font-size: .64rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--emerald-700); background: rgba(28,75,57,.07);
  border: 1px solid rgba(28,75,57,.3); border-radius: 4px; padding: .05em .45em;
  cursor: pointer; transform: translateY(-.1em);
}
.pol-h .pol-edited:hover { background: rgba(28,75,57,.14); }

/* per-selection sizes produced by the formatting bar (execCommand fontSize).
   em-based so they scale with the global text-size setting. */
.pol-body font[size="1"] { font-size: .78em; }
.pol-body font[size="2"] { font-size: .88em; }
.pol-body font[size="3"] { font-size: 1em; }
.pol-body font[size="4"] { font-size: 1.15em; }
.pol-body font[size="5"] { font-size: 1.3em; }
.pol-body font[size="6"] { font-size: 1.5em; }
.pol-body font[size="7"] { font-size: 1.75em; }
.pol-body u { text-decoration-thickness: from-font; }

/* ---- whole-book text settings (the "Aa" popover) ----
   !important beats the per-theme font rules in adp-theme.css; per-selection
   <font face> tags still win on their own element (presentational hint). */
.doc.custom-font .pol-body, .doc.custom-font .pol-h, .doc.custom-font .sec-title,
.doc.custom-font .toc h2, .doc.custom-font .toc-colhead, .doc.custom-font .toc-row,
.doc.custom-font .ts-head,
.doc.custom-font .signoff h2, .doc.custom-font .signoff p,
.doc.custom-font .prep h3, .doc.custom-font .prep-row, .doc.custom-font .sig-cap,
.doc.custom-font .cv-kicker, .doc.custom-font h1.cv-co, .doc.custom-font .cv-title,
.doc.custom-font .cv-brand, .doc.custom-font .cv-foot, .doc.custom-font .cv-draftdate,
.doc.custom-font .scaffold-note {
  font-family: var(--doc-font-custom) !important;
}
.doc.custom-size .pol-body { font-size: calc(.96rem * var(--doc-fs-scale)) !important; }
.doc.custom-size .signoff p { font-size: calc(.96rem * var(--doc-fs-scale)) !important; }
.doc.custom-size .toc-row { font-size: calc(.9rem * var(--doc-fs-scale)) !important; }

/* ADP-theme-only cover/TOC elements — hidden in the default Charter theme */
.cv-band, .cv-draft-mark, .cv-draftdate, .toc-colhead { display: none; }

/* ---- sample gating (locked preview) ---- */
.doc.locked { -webkit-user-select: none; user-select: none; }
.locked-part { filter: blur(6px); opacity: .5; pointer-events: none; -webkit-user-select: none; user-select: none; }
.lock-gate {
  position: relative; z-index: 5; max-width: 560px; margin: 6px auto 28px;
  background: var(--cream); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: 30px 32px; text-align: center;
}
.lock-gate .lg-ic { font-size: 2rem; line-height: 1; }
.lock-gate .lg-title { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; color: var(--ink); margin: .5rem 0 .5rem; }
.lock-gate .lg-sub { font-family: var(--font-ui); font-size: .92rem; color: var(--ink-soft); line-height: 1.55; margin: 0 auto 1.3rem; max-width: 42ch; }
.lock-gate .lg-btn { font-family: var(--font-ui); }

/* skeleton bars shown in locked sections (no real text in the DOM) */
.locked-skel { display: flex; flex-direction: column; gap: 9px; padding: 2px 0 4px; }
.locked-skel .sk { height: 9px; border-radius: 4px; background: rgba(21,35,27,.13); display: block; }
.locked-skel .sk.w2 { width: 82%; }
.locked-skel .sk.w3 { width: 64%; }

/* ---- acknowledgment / sign-off page ---- */
.signoff h2 { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; color: var(--emerald-900); margin-bottom: 1rem; }
.signoff p { font-size: .96rem; line-height: 1.62; color: #233029; margin: 0 0 .9em; }
.sig-grid { display: grid; grid-template-columns: 1.4fr 1.4fr 1fr; gap: 22px; margin: 2.4rem 0 1rem; }
.sig-cell .sig-line { border-bottom: 1.5px solid var(--ink-2); height: 34px; }
.sig-cell .sig-cap { font-family: var(--font-ui); font-size: .72rem; color: var(--ink-soft); margin-top: .35rem; letter-spacing: .02em; }
.prep { margin-top: 2.2rem; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--r-md); background: rgba(28,75,57,.035); }
.prep h3 { font-family: var(--font-ui); font-size: .76rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ochre-600); margin: 0 0 .9rem; font-weight: 700; }
.prep-row { display: flex; align-items: baseline; gap: 14px; padding: .42rem 0; border-bottom: 1px dotted var(--line); font-family: var(--font-ui); }
.prep-row:last-child { border-bottom: none; }
.prep-l { flex: 0 0 200px; font-size: .82rem; color: var(--ink-soft); }
.prep-v { flex: 1 1 auto; font-size: .92rem; font-weight: 600; color: var(--ink); }
.prep-blank { display: inline-block; min-width: 160px; border-bottom: 1px solid var(--line-strong); height: 1em; }

/* =========================================================== PRINT / PDF == */
@media print {
  @page { size: Letter; margin: 0.85in 0.8in; }
  html, body { background: #fff !important; }
  body::before { display: none !important; }            /* no grain in print */
  .app-bar, .form-panel, .preview-toolbar, .mobile-toggle, .site-head, .site-foot { display: none !important; }
  .modal-backdrop, .fmt-bar, .docstyle-pop { display: none !important; }
  /* Locked sample: never expose locked content in the printout — this closes the
     Ctrl+P / "Print to PDF" bypass. Only the free teaser (cover, contents, first
     section) prints, followed by the locked notice. */
  .doc.locked .locked-part { display: none !important; }
  .doc.locked .lock-gate {
    display: block !important; box-shadow: none !important; border: 1px solid #999;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .doc.locked .lock-gate .lg-btn { display: none !important; }
  .app, .app-main, .preview-panel, .preview-scroll { display: block !important; height: auto !important; overflow: visible !important; }
  .preview-panel { background: #fff !important; }
  .preview-scroll { padding: 0 !important; }

  .doc { width: 100% !important; margin: 0 !important; }
  .page {
    box-shadow: none !important; border: none !important; border-radius: 0 !important;
    padding: 0 !important; margin: 0 !important; background: #fff !important;
  }
  .page::after { display: none !important; }
  .cover { min-height: 80vh; page-break-after: always; }
  .toc { page-break-after: always; }
  .signoff { page-break-before: always; }
  .sig-grid { break-inside: avoid; }
  .sec { page-break-inside: auto; }
  .pol { page-break-inside: avoid; }
  .sec-title { page-break-after: avoid; }
  .pol-h { page-break-after: avoid; }
  .tok.pulse { background: transparent !important; animation: none !important; }
  .tok.empty { background: transparent; color: inherit; border-bottom: none; font-style: normal; }
  .pol-h .pol-edited { display: none !important; }
  .pol-body[contenteditable="true"] { outline: none !important; background: transparent !important; }
  .pol-body[contenteditable="true"]::after { display: none !important; }
  .page-foot { display: none; }
}
