/* ==========================================================================
   MFR FORGE — visual design
   Aesthetic: "flight-line office" — deep Air Force ultramarine chrome, warm
   paper preview, condensed display type (Oswald) over Public Sans, with a
   thin gold service stripe as the accent.

   THEMING (Theme Agent): every surface color routes through the variables
   below. html[data-theme="dark"] overrides them for dark mode. The preview
   sheet (.sheet) intentionally does NOT use theme variables — the document
   preview, like the Word and PDF exports, is always official white-page
   style in both themes.
   ========================================================================== */

:root {
  --af-ultra: #002554;
  --af-blue: #00308f;
  --af-steel: #33507a;
  --af-sky: #dbe4f0;
  --gold: #d3a625;
  --gold-bright: #ffc72c;
  --paper: #fdfcf7;
  --bg: #eef1f6;
  --ink: #182233;
  --muted: #5b6b82;
  --line: #ccd6e4;
  --err: #b3261e;
  --err-bg: #fbeceb;
  --err-border: #e3b7b4;
  --warn: #9a6a00;
  --warn-bg: #fdf3d7;
  --ok: #1d6f42;

  --card-bg: #ffffff;
  --card-head-bg: linear-gradient(180deg, #ffffff, #f5f8fc);
  --row-bg: #fbfcfe;
  --input-bg: #fbfcfe;
  --panel-bg: #ffffff;
  --btn-bg: #ffffff;
  --btn-hover: var(--af-sky);
  --tip-bg: var(--af-ultra);
  --tip-text: #eaf0fa;
  --info-bg: #eef3fb;
  --banner-bg: linear-gradient(180deg, #fff8e1, #ffefc2);
  --banner-text: #6b4e00;
  --ph-mark: #ffe08a;
  --ph-mark-text: #493a00;
  --topbar-bg: linear-gradient(180deg, var(--af-ultra) 0%, #001133 130%);

  --radius: 10px;
  --shadow: 0 2px 6px rgba(10, 25, 60, .08), 0 12px 32px rgba(10, 25, 60, .10);
  --font-ui: "Public Sans", system-ui, sans-serif;
  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-doc: "Times New Roman", Times, serif;

  --body-bg:
    radial-gradient(1200px 400px at 85% -10%, rgba(0, 48, 143, .10), transparent 60%),
    repeating-linear-gradient(-45deg, transparent 0 34px, rgba(0, 37, 84, .022) 34px 36px),
    var(--bg);
}

/* ------------------------------- dark mode ------------------------------- */

html[data-theme="dark"] {
  --bg: #0d1420;
  --ink: #dfe7f3;
  --muted: #93a3ba;
  --line: #2b3b55;
  --af-sky: #1a2a44;
  --af-steel: #9db4d4;

  --err: #ff8f86;
  --err-bg: #3a1d1b;
  --err-border: #6b3733;
  --warn: #ffd06b;
  --warn-bg: #362a10;
  --ok: #6fd39a;

  --card-bg: #141e30;
  --card-head-bg: linear-gradient(180deg, #17233a, #121c2e);
  --row-bg: #101a2b;
  --input-bg: #0d1626;
  --panel-bg: #141e30;
  --btn-bg: #1a2740;
  --btn-hover: #223252;
  --tip-bg: #dfe7f3;
  --tip-text: #10203c;
  --info-bg: #16263f;
  --banner-bg: linear-gradient(180deg, #2c230a, #241c08);
  --banner-text: #ffd984;
  --ph-mark: #6b5312;
  --ph-mark-text: #ffe4a1;
  --topbar-bg: linear-gradient(180deg, #001030 0%, #000a1d 130%);

  --shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .45);
  --body-bg:
    radial-gradient(1200px 400px at 85% -10%, rgba(0, 72, 200, .12), transparent 60%),
    repeating-linear-gradient(-45deg, transparent 0 34px, rgba(120, 160, 220, .02) 34px 36px),
    var(--bg);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--body-bg);
  min-height: 100vh;
  transition: background .25s, color .25s;
}

/* ------------------------------- top bar -------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; flex-wrap: wrap; gap: 12px 20px;
  align-items: center; justify-content: space-between;
  padding: 12px 22px;
  background: var(--topbar-bg);
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 4px 18px rgba(0, 10, 30, .35);
}
.brand { display: flex; align-items: center; gap: 14px; color: #fff; }
.brand h1 {
  margin: 0; font-family: var(--font-display);
  font-weight: 600; font-size: 1.45rem; letter-spacing: .14em; color: #fff;
}
.brand h1 + p { margin: 2px 0 0; font-size: .74rem; color: #a9bcd8; letter-spacing: .02em; }
.brand-roundel {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0 26%, #b3261e 27% 40%, #fff 41% 55%, var(--af-blue) 56% 100%);
  border: 2px solid var(--gold);
  display: grid; place-items: center; flex: none;
}
.brand-roundel span {
  width: 10px; height: 10px; border-radius: 2px;
  clip-path: polygon(50% 0, 63% 38%, 100% 38%, 69% 60%, 80% 100%, 50% 76%, 20% 100%, 31% 60%, 0 38%, 37% 38%);
  transform: scale(1.5);
  background: var(--af-blue);
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar-sep { width: 1px; height: 22px; background: rgba(255, 255, 255, .25); }

/* -------------------------------- buttons ------------------------------- */

.btn {
  font-family: var(--font-ui); font-size: .82rem; font-weight: 600;
  padding: 7px 13px; border-radius: 7px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .08); color: #eaf0fa;
  transition: background .15s, transform .08s, border-color .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: rgba(255, 255, 255, .18); }
.btn:active { transform: translateY(1px); }
.btn-gold {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2a2005; border-color: #b28d17; font-weight: 700;
}
.btn-gold:hover { background: linear-gradient(180deg, #ffd75e, var(--gold)); }

/* Export buttons match their document brand: Microsoft Word blue
   (#185ABD, hover #2B579A) and Adobe Acrobat red (#C41230/#DA1F26 family).
   White text on both exceeds WCAG AA contrast (Word blue 6.4:1, Acrobat
   red 6.9:1); the same explicit colors are used in light and dark mode. */
.btn-word {
  background: linear-gradient(180deg, #2B7CD3, #185ABD);
  color: #fff; border-color: #124a9e; font-weight: 700;
}
.btn-word:hover { background: linear-gradient(180deg, #3d8ce0, #1e63c9); }
.btn-word:focus-visible { outline: 2px solid #9cc3f5; outline-offset: 2px; }
.btn-word:active { background: #124a9e; }
.btn-pdf {
  background: linear-gradient(180deg, #E2403C, #C41230);
  color: #fff; border-color: #9e0e26; font-weight: 700;
}
.btn-pdf:hover { background: linear-gradient(180deg, #ef5350, #d41836); }
.btn-pdf:focus-visible { outline: 2px solid #f5a9a4; outline-offset: 2px; }
.btn-pdf:active { background: #9e0e26; }
/* disabled (blocked by validation errors): keep the brand hue, muted */
.btn-word:disabled, .btn-pdf:disabled { color: rgba(255,255,255,.75); }
.btn-amber { background: rgba(255, 199, 44, .16); border-color: rgba(255, 199, 44, .5); color: #ffe9a8; }
.btn-amber:hover { background: rgba(255, 199, 44, .28); }
.btn-ghost { background: transparent; }
.draft-select { max-width: 180px; }
select.btn option { color: #182233; background: #fff; }

/* form-area buttons (theme-aware) */
.card .btn, .fab {
  background: var(--btn-bg); color: var(--ink); border: 1px solid var(--line);
}
.card .btn:hover, .fab:hover { background: var(--btn-hover); }
.btn-add { width: 100%; justify-content: center; border-style: dashed !important; color: var(--af-blue) !important; font-weight: 700; }
html[data-theme="dark"] .btn-add { color: #7fa7ff !important; }
.btn-xs { padding: 3px 8px; font-size: .74rem; border-radius: 5px; }
.btn-xs.danger { color: var(--err) !important; border-color: var(--err-border) !important; }
.btn-xs.danger:hover { background: var(--err-bg); }
.btn-ai {
  background: linear-gradient(180deg, #f4f0ff, #e8e2fa) !important;
  border-color: #c9bdec !important; color: #4b3a86 !important;
  white-space: nowrap; align-self: flex-start;
}
.btn-ai:hover { background: #e4dcf8 !important; }
html[data-theme="dark"] .btn-ai {
  background: linear-gradient(180deg, #2a2350, #221c40) !important;
  border-color: #4a3f80 !important; color: #c9bdf5 !important;
}

/* -------------------------------- layout -------------------------------- */

.layout {
  display: grid; grid-template-columns: minmax(430px, 46%) 1fr;
  gap: 22px; padding: 22px; max-width: 1700px; margin: 0 auto;
  align-items: start;
}
.form-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.preview-col { position: sticky; top: 86px; min-width: 0; }

/* --------------------------------- cards -------------------------------- */

.card {
  background: var(--card-bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px; cursor: pointer; user-select: none;
  background: var(--card-head-bg);
  border-bottom: 1px solid var(--line);
}
.card-head h2 {
  margin: 0; font-family: var(--font-display); font-weight: 500;
  font-size: 1.02rem; letter-spacing: .05em; text-transform: uppercase;
  color: var(--ink); display: flex; align-items: center; gap: 10px;
}
.card-index {
  display: inline-grid; place-items: center; width: 24px; height: 24px;
  background: var(--af-ultra); color: var(--gold-bright);
  font-family: var(--font-display); font-size: .8rem; border-radius: 6px;
}
.chev { color: var(--muted); transition: transform .2s; }
.card.collapsed .chev { transform: rotate(-90deg); }
.card.collapsed .card-body { display: none; }
.card-body { padding: 16px 18px 18px; }

.subhead {
  font-family: var(--font-display); font-weight: 500; letter-spacing: .06em;
  text-transform: uppercase; font-size: .8rem; color: var(--af-steel);
  border-top: 1px dashed var(--line); margin: 18px 0 10px; padding-top: 14px;
}
.hint { font-size: .8rem; color: var(--muted); margin: 0 0 12px; line-height: 1.5; }

/* --------------------------------- fields ------------------------------- */

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2 .span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: .74rem; font-weight: 700; color: var(--af-steel); letter-spacing: .01em; }
.field input[type="text"], .field input[type="date"], .field select, textarea.para-text {
  font-family: var(--font-ui); font-size: .88rem; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--input-bg); width: 100%;
  transition: border-color .15s, box-shadow .15s, background .25s, color .25s;
}
.field input:focus, .field select:focus, textarea.para-text:focus {
  outline: none; border-color: var(--af-blue);
  box-shadow: 0 0 0 3px rgba(0, 88, 220, .18);
}
html[data-theme="dark"] .field input:focus,
html[data-theme="dark"] .field select:focus,
html[data-theme="dark"] textarea.para-text:focus { border-color: #4d7dd6; }
.field input::placeholder, textarea.para-text::placeholder { color: var(--muted); opacity: .75; }
html[data-theme="dark"] input[type="date"] { color-scheme: dark; }
.field.check { flex-direction: row; align-items: center; gap: 8px; font-size: .82rem; color: var(--ink); padding: 4px 0; }
.field.check input { width: 16px; height: 16px; accent-color: var(--af-blue); flex: none; }

/* form controls that still contain [INSERT ...] placeholder text */
.has-placeholder {
  border-color: var(--gold) !important;
  box-shadow: inset 3px 0 0 var(--gold);
}

/* tooltips (theme-aware, readable in both modes) */
.tip {
  display: inline-grid; place-items: center; width: 15px; height: 15px;
  border-radius: 50%; background: var(--af-sky); color: var(--af-blue);
  font-style: normal; font-size: .66rem; font-weight: 800; cursor: help;
  position: relative; margin-left: 4px; vertical-align: 1px;
}
html[data-theme="dark"] .tip { color: #9dc0ff; }
.tip::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) scale(.95);
  width: 240px; padding: 8px 10px; border-radius: 8px;
  background: var(--tip-bg); color: var(--tip-text);
  font-weight: 400; font-size: .74rem; line-height: 1.45;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
  z-index: 30; box-shadow: var(--shadow); text-transform: none; letter-spacing: 0;
}
.tip:hover::after { opacity: 1; transform: translateX(-50%) scale(1); }

/* ----------------------------- dynamic rows ------------------------------ */

.item-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.item-row {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  background: var(--row-bg);
  transition: box-shadow .15s, border-color .15s, opacity .15s, background .25s;
}
.item-row.dragging { opacity: .45; }
.item-row.dragover { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(211, 166, 37, .35); }
.item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.item-grow { flex: 1; }
.drag-handle { cursor: grab; color: var(--muted); font-size: .95rem; }
.item-tag {
  font-family: var(--font-display); font-size: .8rem; letter-spacing: .04em;
  background: var(--af-ultra); color: var(--gold-bright);
  padding: 2px 9px; border-radius: 5px;
}
.kind-select {
  font-size: .74rem; padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--line); background: var(--input-bg); color: var(--muted);
}
.signer-fields { display: flex; flex-direction: column; gap: 8px; }

.body-row.depth-1 { margin-left: 22px; }
.body-row.depth-2 { margin-left: 44px; }
.body-row.depth-3 { margin-left: 66px; }
.sub-list { display: flex; flex-direction: column; gap: 10px; }
.item-list > .sub-list { margin-top: 10px; }
.para-edit { display: flex; gap: 8px; align-items: stretch; }
textarea.para-text { resize: vertical; line-height: 1.5; flex: 1; }

/* ------------------------------ live preview ----------------------------- */
/* The sheet is ALWAYS official-document style (white paper, black Times),
   independent of the app theme — matching the Word and PDF exports. */

.preview-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.preview-head h2 {
  margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 1rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink);
}
.preview-note { font-size: .72rem; color: var(--muted); }

.sheet-wrap { overflow: auto; max-height: calc(100vh - 140px); padding: 4px 4px 30px; }
.sheet {
  width: 816px;              /* 8.5in at 96dpi */
  min-height: 1056px;        /* 11in */
  margin: 0 auto;
  background: #fdfcf7;       /* paper — never themed */
  box-shadow: 0 1px 3px rgba(20, 30, 50, .3), 0 18px 44px rgba(20, 30, 50, .28);
  padding: 48px 96px 96px;
  font-family: var(--font-doc); font-size: 16px; /* 12pt at 96dpi */
  line-height: 1.15; color: #000;
  position: relative;
}
.sheet p { margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.pv-blank { min-height: 1.15em; }

.pv-class { text-align: center; font-weight: bold; margin-bottom: 8px; }
.pv-class-bottom { margin-top: 24px; margin-bottom: 0; }

.pv-letterhead { text-align: center; margin-bottom: 26px; min-height: 62px; }
/* Position (left/top/size) is set inline from FORMAT.seal so preview, Word,
   and PDF share one geometry; anchored to the .sheet page, not the text. */
.pv-seal { position: absolute; }
.pv-lh1, .pv-lh2 {
  font-family: "Copperplate Gothic Bold", "Copperplate", serif;
  color: #355e93; font-weight: 700; letter-spacing: .02em;
}
.pv-lh1 { font-size: 16px; }
.pv-lh2 { font-size: 14px; }

.pv-date { text-align: right; }
.pv-from { display: flex; }
.pv-fromtab { margin-left: 8px; }
.pv-from:first-of-type .pv-fromtab { margin-left: 12px; }
.pv-missing {
  background: #fff3cd; color: #7a5c00; border: 1px dashed #d9b94c;
  padding: 0 4px; border-radius: 3px; font-size: .85em;
}
.sheet mark.ph { background: #ffe08a; color: #493a00; border-radius: 2px; padding: 0 2px; }

/* Dual signatures: two TOP-ALIGNED columns starting on the same line —
   junior at the left margin, senior at 4.5". Long lines wrap inside their
   own column; blocks can never overlap and are never diagonal/staggered. */
.pv-dualwrap { display: flex; align-items: flex-start; break-inside: avoid; }
.pv-dcol { min-width: 0; overflow-wrap: break-word; }
.pv-indhead { display: flex; justify-content: space-between; }
.pv-keep { display: block; }

/* --------------------------- validation drawer --------------------------- */

.validation-panel {
  position: fixed; top: 0; right: -480px; width: min(460px, 94vw); height: 100vh;
  background: var(--panel-bg); z-index: 90; box-shadow: -12px 0 40px rgba(0, 10, 30, .35);
  transition: right .28s cubic-bezier(.2, .8, .3, 1);
  display: flex; flex-direction: column;
  border-left: 3px solid var(--gold);
}
.validation-panel.open { right: 0; }
.validation-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--af-ultra); color: #fff;
}
.validation-head h2 { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 1rem; letter-spacing: .08em; text-transform: uppercase; }
.validation-head .btn { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.3); }
.validation-body { overflow: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.val-summary { display: flex; gap: 8px; margin-bottom: 6px; }
.val-pill { font-size: .72rem; font-weight: 700; padding: 3px 10px; border-radius: 20px; }
.val-err { background: var(--err-bg); color: var(--err); }
.val-warn { background: var(--warn-bg); color: var(--warn); }
.val-info { background: var(--info-bg); color: var(--af-blue); }
html[data-theme="dark"] .val-info { color: #8fb3f5; }
/* Validation items are BUTTONS: click jumps to (and highlights) the exact
   field/row the issue points at. Sorted Errors -> Warnings -> Notes. */
.val-item {
  display: flex; flex-direction: column; gap: 4px;
  font-size: .82rem; line-height: 1.45; padding: 9px 11px; border-radius: 7px;
  border: none; border-left: 3px solid transparent; color: var(--ink);
  text-align: left; cursor: pointer; width: 100%;
  font-family: var(--font-ui);
  transition: transform .1s, box-shadow .15s;
}
.val-item:hover { transform: translateX(-2px); box-shadow: var(--shadow); }
.val-item:focus-visible { outline: 2px solid var(--af-blue); outline-offset: 2px; }
.val-item.val-error { background: var(--err-bg); border-left-color: var(--err); }
.val-item.val-warning { background: var(--warn-bg); border-left-color: var(--warn); }
.val-item.val-info { background: var(--info-bg); border-left-color: var(--af-blue); }
.val-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.val-type {
  font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  padding: 2px 8px; border-radius: 10px; color: #fff;
}
.val-type-error { background: var(--err); }
.val-type-warning { background: var(--warn); color: #fff; }
.val-type-info { background: var(--af-blue); }
html[data-theme="dark"] .val-type-error { color: #2a0503; }
html[data-theme="dark"] .val-type-warning { color: #241a00; }
.val-title { font-weight: 800; }
.val-section { font-size: .68rem; color: var(--muted); margin-left: auto; }
.val-msg { color: var(--ink); }
.val-fix { font-size: .74rem; color: var(--af-steel); font-style: italic; }
.val-agent { font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.val-clean { color: var(--ok); font-weight: 700; }

/* Toolbar state driven by LIVE validation (auto-updates as the user types) */
#btnValidate.has-errors { border-color: #ff8f86; color: #ffd3cf; }
.btn.is-blocked, .btn:disabled {
  opacity: .45; cursor: not-allowed; filter: saturate(.5);
}

/* Jump-to-field highlight: thick outline + pulse motion (accessible — not
   color-only), readable in light AND dark mode, fades out after ~3 s.
   The COLOR MATCHES THE ISSUE TYPE (same families as the panel items):
     .flash-error   -> red    .flash-warning -> amber   .flash-info -> blue
   jumpToIssue() adds .flash-highlight plus one severity class. */
.flash-highlight { --flash: #ffc72c; --flash-rgb: 255, 199, 44; }
.flash-highlight.flash-error   { --flash: #ff4438; --flash-rgb: 255, 68, 56; }
.flash-highlight.flash-warning { --flash: #ffb020; --flash-rgb: 255, 176, 32; }
.flash-highlight.flash-info    { --flash: #4c9aff; --flash-rgb: 76, 154, 255; }
@keyframes flashPulse {
  0%   { box-shadow: 0 0 0 6px rgba(var(--flash-rgb), .45); }
  12%  { box-shadow: 0 0 0 12px rgba(var(--flash-rgb), .18); }
  24%  { box-shadow: 0 0 0 6px rgba(var(--flash-rgb), .40); }
  100% { outline-color: transparent; box-shadow: 0 0 0 0 rgba(var(--flash-rgb), 0); }
}
.flash-highlight {
  outline: 3px solid var(--flash);
  outline-offset: 2px;
  border-radius: 8px;
  animation: flashPulse 3s ease-out forwards;
}

/* --------------------------------- toasts -------------------------------- */

.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--af-ultra); color: #fff; font-size: .82rem; font-weight: 600;
  padding: 10px 18px; border-radius: 30px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(12px); transition: all .3s;
  border-left: 4px solid var(--gold);
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-err { border-left-color: #ff7b72; }

/* ---------------------------------- FAB ---------------------------------- */

.fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  display: none; padding: 12px 18px; border-radius: 30px;
  font-weight: 700; box-shadow: var(--shadow); border: 1px solid var(--line);
}

/* ---------------------------- sample banner ------------------------------ */

.sample-banner {
  position: sticky; top: 0; z-index: 49;
  background: var(--banner-bg);
  border-bottom: 2px solid var(--gold);
  color: var(--banner-text); font-size: .82rem; line-height: 1.5;
  padding: 9px 22px; text-align: center;
}
.sample-banner mark.ph, .toast mark.ph {
  background: var(--ph-mark); color: var(--ph-mark-text);
  border-radius: 2px; padding: 0 3px;
}

/* ------------------------------ print / PDF ------------------------------ */
/* Ctrl+P fallback: prints ONLY the preview sheet at true US Letter size.
   (The primary PDF path is the PDF Export Agent, which paginates itself.)
   Page-break hints mirror the exports: paragraphs and keep-together blocks
   never split, widows/orphans suppressed. */

@media print {
  @page { size: letter; margin: 0; }
  body { background: #fff; }
  .topbar, .form-col, .fab, .validation-panel, .toasts,
  .preview-head, .sample-banner { display: none !important; }
  .layout { display: block; padding: 0; }
  .preview-col { display: block !important; position: static; }
  .sheet-wrap { overflow: visible; max-height: none; padding: 0; }
  .sheet {
    width: 8.5in; min-height: 11in; margin: 0;
    padding: 0.5in 1in 1in;
    box-shadow: none; transform: none !important;
    font-size: 12pt;
  }
  .sheet p { orphans: 2; widows: 2; }
  .pv-para, .pv-ref { break-inside: avoid; }
  .pv-keep { break-inside: avoid; }
  .pv-missing { border: none; background: none; }
  .sheet mark.ph { background: #ffe08a; }
  }

/* ------------------------------- responsive ------------------------------ */

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .preview-col { position: static; display: none; }
  body.show-preview .preview-col { display: block; }
  body.show-preview .form-col { display: none; }
  .fab { display: inline-flex; }
  .sheet { transform-origin: top left; }
}
@media (max-width: 900px) {
  .sheet-wrap { max-height: none; }
  .sheet { transform: scale(.82); margin-bottom: -180px; }
}
@media (max-width: 700px) {
  .grid2 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; }
  .brand h1 + p { display: none; }
  .layout { padding: 12px; }
  .sheet { transform: scale(.44); margin-bottom: -560px; }
  .toolbar { width: 100%; }
}
