/* paper.css — the document itself.
   This stylesheet is the PDF. What print does is stop drawing the application
   around it; the pages are the same nodes, at the same millimetres, either way.
   That is why the preview cannot drift from the output — there is only one. */

.page {
  position: relative;
  background: #fff;
  color: var(--ink, #1a1a1a);
  box-shadow: var(--shadow);
  font-family: var(--doc-font, 'Segoe UI', sans-serif);
  font-size: var(--doc-size, 10pt);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

.page-body { flex: 1; }

.page-head,
.page-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--faint, #9aa5b1);
  font-size: 8pt;
}
.page-head { padding-bottom: 6pt; border-bottom: .5pt solid var(--rule, #d8d8d8); margin-bottom: 10pt; }
.page-foot { padding-top: 6pt; border-top: .5pt solid var(--rule, #d8d8d8); margin-top: 10pt; }
.pageno { font-variant-numeric: tabular-nums; }

.watermark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 76pt;
  font-weight: 800;
  letter-spacing: .08em;
  color: rgba(0, 0, 0, .05);
  transform: rotate(-24deg);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

/* ─────────── the element wrapper ─────────── */

.el {
  position: relative;
  z-index: 1;
  border: 1px solid transparent;
  border-radius: 3px;
  transition: border-color .1s;
}
.el:hover { border-color: rgba(61, 90, 128, .28); }
.el.sel { border-color: var(--sel, #3d5a80); box-shadow: 0 0 0 2px rgba(61, 90, 128, .12); }

.el-bar {
  position: absolute;
  top: -12px;
  right: 4px;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 1px;
  padding: 2px 3px;
  border: 1px solid var(--line, #dfe3e8);
  border-radius: 6px;
  background: var(--panel, #fff);
  box-shadow: 0 2px 8px rgba(16, 24, 40, .1);
  font-family: var(--ui);
  font-size: 11px;
  color: var(--text, #1f2933);
}
.el:hover > .el-bar, .el.sel > .el-bar { display: flex; }

.el-grip { padding: 0 4px; cursor: grab; color: var(--faint, #9aa5b1); }
.el-grip:active { cursor: grabbing; }
.el-name {
  padding: 0 5px;
  color: var(--brand, #2f6b4f);
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .04em;
}
.el-btn {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.el-btn:hover:not(:disabled) { background: var(--panel-2, #f7f8fa); }
.el-btn:disabled { opacity: .25; cursor: default; }
.el-btn.danger:hover { background: var(--danger, #c0392b); color: #fff; }

/* ─────────── editable prose ─────────── */

.prose {
  outline: 0;
  min-height: 1em;
  white-space: pre-wrap;
  border-radius: 2px;
}
.prose:hover { background: rgba(61, 90, 128, .05); }
.prose:focus, .prose.editing { background: rgba(61, 90, 128, .09); box-shadow: 0 0 0 1px rgba(61, 90, 128, .3); }
.prose:empty::before {
  content: attr(data-ph);
  color: #b8bfc7;
}

h1.h { margin: 0; font-size: 20pt; font-weight: 800; letter-spacing: .12em; color: var(--head, #1a1a1a); }
h2.h { margin: 0; font-size: 15pt; font-weight: 700; letter-spacing: .06em; }
h3.h { margin: 0; font-size: 12pt; font-weight: 700; }
.p { margin: 0; }

.block-title {
  margin: 0 0 5pt;
  font-size: 9pt;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent, #e8b21a);
}

/* ─────────── meta / parties / key-value ─────────── */

.meta-grid { display: grid; gap: 8pt; }
.meta-cell { text-align: left; }
.meta-label {
  font-size: 7.5pt;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint, #9aa5b1);
}
.meta-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.meta-date {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
}
.meta-date:hover { background: rgba(61, 90, 128, .05); }

.parties { display: grid; gap: 16pt; text-align: left; }
.party-label {
  margin-bottom: 3pt;
  font-size: 7.5pt;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent, #e8b21a);
}
.party-line { font-size: 9pt; line-height: 1.5; }
.party-line.strong { font-weight: 700; font-size: 10pt; }

.party-event {
  margin-top: 5pt;
  padding: 3pt 6pt;
  border-left: 2pt solid var(--accent, #e8b21a);
  background: var(--band, #faf6e8);
}
.event-label {
  font-size: 7pt;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint, #9aa5b1);
}
.event-name { font-weight: 700; font-size: 10pt; line-height: 1.35; }

.kv-grid { display: grid; gap: 5pt 14pt; text-align: left; }
.kv { display: flex; gap: 6pt; }
.kv-label { flex: 0 0 42%; color: var(--faint, #9aa5b1); font-size: 8.5pt; }
.kv-value { flex: 1; font-weight: 600; font-size: 8.5pt; }

/* ─────────── the item table ─────────── */

table.items {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

table.items th {
  padding: 5pt 6pt;
  background: var(--head, #1a1a1a);
  color: var(--head-text, #fff);
  font-size: 8pt;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: left;
  position: relative;
}
table.items th.a-center { text-align: center; }
table.items th.a-right { text-align: right; }

.th-text { display: inline-block; min-width: 1em; }

.col-menu {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, .16);
  color: inherit;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  opacity: 0;
  transition: opacity .1s;
}
th:hover .col-menu { opacity: 1; }
.col-menu:hover { background: rgba(255, 255, 255, .34); }

.lock { margin-left: 3px; font-size: 7pt; opacity: .8; }

table.items td {
  padding: 0;
  border-bottom: .5pt solid var(--rule, #d8d8d8);
  vertical-align: middle;
}
table.items tbody tr:hover td { background: rgba(61, 90, 128, .035); }

.cell {
  width: 100%;
  padding: 4pt 6pt;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-variant-numeric: tabular-nums;
  outline: 0;
}
.cell:hover { background: rgba(61, 90, 128, .06); }
.cell:focus, .cell.editing {
  background: #fff;
  border-color: var(--sel, #3d5a80);
  box-shadow: 0 0 0 2px rgba(61, 90, 128, .14);
  font-variant-numeric: normal;
}
.cell.computed { color: #3a5a7d; }        /* a figure the column worked out */
.cell.err { color: #c0392b; font-weight: 700; }

td.a-center .cell { text-align: center; }
td.a-right .cell { text-align: right; }

/* internal columns — on the screen, never on the paper */
.internal-col { background: repeating-linear-gradient(45deg, rgba(183, 121, 31, .05) 0 6px, transparent 6px 12px); }
th.internal-col { background: #6b5a3a; }

td.row-tools { width: 16px; border-bottom: 0; }
.row-btn {
  width: 14px;
  height: 16px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #b8bfc7;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  opacity: 0;
}
tr:hover .row-btn { opacity: 1; }
.row-btn:hover { color: var(--sel, #3d5a80); }

tfoot .total-row td {
  padding: 5pt 6pt;
  border-top: 1pt solid var(--ink, #1a1a1a);
  border-bottom: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
tfoot .total-row td.a-center { text-align: center; }
tfoot .total-row td.a-right { text-align: right; }

.contd {
  margin-bottom: 4pt;
  color: var(--faint, #9aa5b1);
  font-size: 8pt;
  font-style: italic;
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4pt;
}
.add-line {
  padding: 2px 8px;
  border: 1px dashed var(--rule, #d8d8d8);
  border-radius: 4px;
  background: transparent;
  color: var(--faint, #9aa5b1);
  cursor: pointer;
  font-family: var(--ui);
  font-size: 10px;
}
.add-line:hover { border-color: var(--sel, #3d5a80); color: var(--sel, #3d5a80); }
.table-hint { color: #c2c8cf; font-family: var(--ui); font-size: 9.5px; }

/* ─────────── totals ─────────── */

.totals { display: inline-flex; flex-direction: column; gap: 1pt; text-align: left; margin-left: auto; }

.t-row {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 6pt;
  padding: 2.5pt 6pt;
  border-bottom: .5pt solid var(--rule, #d8d8d8);
}
.t-row:hover { background: rgba(61, 90, 128, .04); }
.t-label { flex: 1; font-size: 8.5pt; letter-spacing: .05em; text-transform: uppercase; color: var(--ink, #1a1a1a); }
.t-val {
  min-width: 92pt;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 9.5pt;
}
.t-val.neg { color: #9b2c2c; }
.t-val.err { color: #c0392b; font-weight: 700; }

.t-pct { display: flex; align-items: baseline; font-size: 8pt; color: var(--faint, #9aa5b1); }
.t-rate {
  width: 30px;
  padding: 0 2px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--accent, #e8b21a);
  font: inherit;
  font-weight: 700;
  text-align: right;
}
.t-rate:hover { border-color: var(--rule, #d8d8d8); }
.t-rate:focus { border-color: var(--sel, #3d5a80); background: #fff; outline: 0; }

.t-row.strong {
  margin-top: 2pt;
  border-top: 1pt solid var(--ink, #1a1a1a);
  border-bottom: 2pt double var(--ink, #1a1a1a);
  background: var(--band, #faf6e8);
}
.t-row.strong .t-label { font-weight: 800; }
.t-row.strong .t-val { font-weight: 800; font-size: 11pt; }
.t-row.after { border-bottom-style: dashed; }
.t-row.after .t-label { color: var(--faint, #9aa5b1); }

.t-menu {
  position: absolute;
  right: -16px;
  top: 3px;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #b8bfc7;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  opacity: 0;
}
.t-row:hover .t-menu { opacity: 1; }
.t-menu:hover { color: var(--sel, #3d5a80); }

/* ─────────── words, terms, bank, signature ─────────── */

.words {
  padding: 4pt 6pt;
  border-left: 2pt solid var(--accent, #e8b21a);
  background: var(--band, #faf6e8);
  font-size: 9pt;
  font-style: italic;
  text-align: left;
}

ol.terms, ul.terms { margin: 0; padding-left: 14pt; text-align: left; }
.terms li { margin-bottom: 2pt; font-size: 8.5pt; line-height: 1.5; position: relative; }
.term { display: inline-block; width: calc(100% - 16px); }
.row-x {
  width: 14px;
  height: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #cbd2d9;
  cursor: pointer;
  font-size: 9px;
  opacity: 0;
}
.terms li:hover .row-x { opacity: 1; }
.row-x:hover { color: var(--danger, #c0392b); }

.sign { display: inline-block; min-width: 150pt; text-align: center; }
.sign-note { color: var(--faint, #9aa5b1); font-size: 8pt; }
.sign-line { height: 26pt; border-bottom: .5pt solid var(--ink, #1a1a1a); margin-bottom: 3pt; }
.sign-name { font-weight: 700; font-size: 9.5pt; }
.sign-role { color: var(--faint, #9aa5b1); font-size: 8pt; }
.sign-company { font-size: 8.5pt; margin-top: 2pt; }
.sign-date { color: var(--faint, #9aa5b1); font-size: 8pt; margin-top: 4pt; }
.sign-img { max-height: 34pt; max-width: 150pt; object-fit: contain; margin-bottom: 2pt; }

/* the UPI pay-to code */
.qr-img { display: inline-block; line-height: 0; }
.qr-img svg { display: block; }
.qr-empty {
  padding: 20pt; border: 1px dashed var(--rule, #d8d8d8);
  color: var(--faint, #9aa5b1); font-size: 8.5pt; border-radius: 4px;
}
.qr-caption { color: var(--faint, #9aa5b1); font-size: 8pt; margin-top: 3pt; }

/* inline formatting inside a rich prose block */
.prose.rich a { color: var(--accent, #3d5a80); text-decoration: underline; }
.prose.rich b, .prose.rich strong { font-weight: 700; }

.doc-rule { margin: 0; border: 0; border-top: 1px solid var(--rule, #d8d8d8); }
.doc-img { display: inline-block; max-width: 100%; cursor: pointer; }
.img-drop {
  width: 100%;
  padding: 18pt;
  border: 1px dashed var(--rule, #d8d8d8);
  border-radius: 4px;
  background: transparent;
  color: var(--faint, #9aa5b1);
  cursor: pointer;
  font-family: var(--ui);
  font-size: 11px;
}
.img-drop:hover { border-color: var(--sel, #3d5a80); color: var(--sel, #3d5a80); }

.pagebreak-mark {
  padding: 3pt;
  border-top: 1px dashed var(--sel, #3d5a80);
  color: var(--sel, #3d5a80);
  font-family: var(--ui);
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
  text-align: center;
  opacity: .55;
}

/* ─────────── the internal margin block ─────────── */

.margin-box {
  padding: 6pt 8pt;
  border: 1px dashed #b7791f;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, rgba(183, 121, 31, .05) 0 8px, transparent 8px 16px);
  text-align: left;
}
.margin-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5pt;
  color: #8a5a12;
  font-family: var(--ui);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.badge {
  padding: 1px 6px;
  border-radius: 999px;
  background: #b7791f;
  color: #fff;
  font-size: 8px;
  letter-spacing: .04em;
}
.margin-grid { display: flex; gap: 16pt; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat-label { color: #a08048; font-family: var(--ui); font-size: 8px; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-variant-numeric: tabular-nums; font-size: 10pt; font-weight: 700; }
.stat.good .stat-value { color: #2f855a; }
.stat.bad .stat-value { color: #c0392b; }

.spacer { width: 100%; }

/* ═══════════════════════════════════════════════════════════════
   PRINT — the PDF.
   Everything the application drew is switched off, and the pages
   that remain are exactly the pages that were on the screen.
   ═══════════════════════════════════════════════════════════════ */

@media print {
  @page { size: A4; margin: 0; }

  html, body { height: auto; overflow: visible; background: #fff; }

  .toolbar, .panel, .status, .toasts, .menu, .backdrop { display: none !important; }

  .shell { display: block; height: auto; }

  .canvas {
    display: block;
    padding: 0;
    overflow: visible;
    background: #fff;
  }
  .canvas > .page { zoom: 1 !important; }   /* the screen's zoom is not the paper's */

  .page {
    box-shadow: none;
    margin: 0;
    break-after: page;
    page-break-after: always;
  }
  .page:last-child { break-after: auto; page-break-after: auto; }

  /* Nothing the editor added to work with survives onto the paper. */
  .el-bar, .col-menu, .row-btn, .t-menu, .add-line, .table-tools,
  .row-x, .drop-line, .pagebreak-mark, .img-drop { display: none !important; }

  .el, .el:hover, .el.sel { border-color: transparent !important; box-shadow: none !important; }

  .prose, .prose:hover, .prose:focus,
  .cell, .cell:hover, .cell:focus,
  .meta-date, .t-rate {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    color: inherit !important;
  }

  td.row-tools { display: none; }
  table.items tbody tr:hover td { background: transparent; }

  /* The internal columns and the margin block are the reason this exists:
     they are on the screen for you, and they are never on the paper for them. */
  .internal-col, th.internal-col, .internal, .margin-box, .el[data-type="margin"] {
    display: none !important;
  }

  /* A line item is not split down the middle by a page boundary. */
  tr, .t-row, .el { break-inside: avoid; page-break-inside: avoid; }

  .cell { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.items th, .t-row.strong, .words, .page { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Printing is driven from the app, so the class is set a frame before the
   dialog opens — this keeps the on-screen state from flashing. */
body.printing .toolbar,
body.printing .panel,
body.printing .status { visibility: hidden; }

/* ─────────── a link that is still a link in the PDF ───────────
   The browser's print engine writes a real link annotation for every <a href> it
   finds, so this is not a picture of a button: the client who opens the emailed
   PDF can press it. Which means the ONE thing this must never do is disappear, or
   lose its href, when printing. */

a.doc-btn {
  display: inline-block;
  padding: 7pt 18pt;
  border-radius: 5pt;
  background: var(--accent, #e8b21a);
  color: #fff;
  font-size: 9.5pt;
  font-weight: 700;
  letter-spacing: .03em;
  text-decoration: none;
  cursor: pointer;
}
a.doc-btn:hover { filter: brightness(1.08); }

a.doc-link {
  color: var(--accent, #e8b21a);
  font-size: 9.5pt;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.link-text { display: inline-block; min-width: 2em; }
.link-url {
  margin-top: 3pt;
  color: var(--faint, #9aa5b1);
  font-size: 7.5pt;
  word-break: break-all;
}
.link-empty { text-align: center; }

@media print {
  /* The colour is the affordance. Without this, a button prints as white-on-white
     and nobody knows there was ever a button there. */
  a.doc-btn {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color: #fff !important;
    text-decoration: none !important;
  }
  a.doc-link {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    text-decoration: underline !important;
  }

  /* The editor makes every prose node hover and focus. On paper that would put a
     grey box behind the words on the button. */
  a.doc-btn .prose, a.doc-link .prose,
  a.doc-btn .prose:hover, a.doc-link .prose:hover {
    background: transparent !important;
    box-shadow: none !important;
    color: inherit !important;
  }

  /* A button that goes nowhere is worse on a client's desk than no button at all. */
  .link-empty { display: none !important; }
}
