.docgen-totals-row.grand {
  background: var(--accent-dim, #ffe4d6);
  padding: 10px 12px;
  border-radius: var(--radius, 6px);
  margin-top: 4px;
}
.docgen-totals-row.grand span:last-child {
  color: var(--accent, #ff6b35);
}
#rowBalanceDue {
  background: var(--ink-800, #23262e);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius, 6px);
}
#rowBalanceDue span {
  color: #fff !important;
  font-weight: 700;
}

@media print {
  #m_paymentTerms {
    width: 100% !important;
    min-width: 320px !important;
  }
}

@media print {
  input[type="date"]::-webkit-calendar-picker-indicator {
    display: none !important;
  }
  input[type="date"] {
    -webkit-appearance: none;
  }
  .docgen-table .item-amount {
    color: var(--text-on-paper, #23262e) !important;
    font-weight: 700 !important;
  }
  .docgen-totals-row.grand span:first-child {
    color: var(--text-on-paper, #23262e) !important;
    font-weight: 700 !important;
  }
}

/* ============================================================
   document-generator.css
   Layers on top of main.css. Scoped under .docgen-* so it never
   collides with the tip-calculator/word-counter/etc. styles.
   ============================================================ */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  .rail, .site-footer, .tool-sidebar, .main-content {
    display: none !important;
  }
  .app-shell, .main-column, .tool-panel, .tool-main {
    display: block !important;
    height: auto !important;
    min-height: 0 !important;
  }
  .docgen-panel {
    position: static !important;
    margin: 0 auto !important;
  }
}

/* ---- ADD-ON: print-time hide for empty optional fields + guaranteed bold total ---- */
@media print {
  @page {
    size: A4;
    margin: 10mm 12mm;
  }
  .print-hide { display: none !important; }
  .docgen-totals-row.grand,
  .docgen-totals-row.grand span { font-weight: 700 !important; }
  .docgen-table thead th {
    background: var(--ink-900, #1a1d23) !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .docgen-table thead th:first-child { border-top-left-radius: 4px; }
  .docgen-table thead th:last-child { border-top-right-radius: 4px; }
  .docgen-totals-row.grand {
    font-size: 18px !important;
    border-top: 2px solid var(--ink-900, #1a1d23) !important;
    padding-top: 8px !important;
  }
  /* Keep the item table and the totals/notes/terms block from splitting
     across a page boundary — this is what was pushing totals to page 2. */
  .docgen-panel {
    gap: 12px !important;
  }
  .docgen-topline, .docgen-grid2 {
    margin-bottom: 4px !important;
  }
  .docgen-table-wrap,
  .docgen-totals {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .docgen-field textarea {
    margin-bottom: 2px !important;
  }
  /* GST invoice tool: this page has more content (HSN column, per-HSN
     summary table, amount-in-words) than the other doc types, so it
     needs tighter print spacing to still fit on one A4 page. */
  .gst-summary-table {
    margin-top: 4px !important;
  }
  .gst-summary-table thead th {
    padding: 4px 8px !important;
    font-size: 10.5px !important;
  }
  .gst-summary-table tbody td {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }
  #outAmountWords {
    font-size: 12px !important;
  }
  .docgen-panel {
    padding: 10px !important;
  }
  .docgen-table thead th {
    padding: 5px 8px !important;
  }
  .docgen-table tbody td {
    padding: 3px !important;
  }
  .docgen-grid2 {
    gap: 10px !important;
  }
  .docgen-meta-row {
    gap: 4px !important;
  }
  .docgen-field {
    margin-bottom: 0 !important;
  }
  .docgen-field label {
    margin-bottom: 1px !important;
    font-size: 10.5px !important;
  }
  .docgen-field input,
  .docgen-field textarea {
    padding: 3px 6px !important;
    font-size: 12px !important;
  }
  .docgen-field textarea {
    min-height: 0 !important;
  }
  .docgen-logo-preview {
    min-height: 16px !important;
    min-width: 0 !important;
  }
  .docgen-topline {
    gap: 6px !important;
    margin-bottom: 0 !important;
  }
  .docgen-doclabel {
    font-size: 20px !important;
  }
  .docgen-numfield {
    font-size: 11px !important;
  }
  .docgen-numfield input {
    width: 50px !important;
    padding: 2px 4px !important;
  }
  /* GST invoice only: Chrome won't fragment a CSS grid across a page
     break, so as long as Notes/Terms + Totals stay side-by-side in a
     grid, the whole block jumps to page 2 as soon as it doesn't fit
     what's left of page 1. Stack it instead so it can flow/break
     naturally like normal text. */
  .docgen-bottom-grid-gst {
    display: block !important;
  }
  .docgen-bottom-grid-gst > div:first-child {
    margin-bottom: 6px !important;
  }
  .docgen-bottom-grid-gst .docgen-totals {
    max-width: 100% !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
  }
  .docgen-bottom-grid-gst .docgen-totals-row {
    font-size: 12px !important;
  }
  .docgen-bottom-grid-gst .docgen-totals {
    gap: 4px !important;
  }
  .docgen-bottom-grid-gst .docgen-field select,
  .docgen-bottom-grid-gst .docgen-field input {
    padding: 3px 6px !important;
    font-size: 12px !important;
  }
  .docgen-bottom-grid-gst .docgen-field label {
    margin-bottom: 1px !important;
    font-size: 10px !important;
  }
  /* Guaranteed one-page fit: instead of chasing every last pixel of
     overflow individually, shrink the whole GST invoice panel down
     for print. width is inflated by the inverse of the scale so the
     content still spans the full printable page width after shrinking. */
  body.gst-invoice-print .docgen-panel {
    zoom: 0.75;
  }
}

.docgen-panel {
  background: #fff;
  border: 1px solid var(--panel-border, #383c46);
  border-radius: var(--radius, 6px);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.docgen-topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
}

.docgen-doclabel {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: 0.02em;
}

.docgen-logo-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  min-width: 120px;
  cursor: pointer;
}

.docgen-numfield {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.docgen-numfield input { width: 70px; padding: 6px 8px; border: 1px solid var(--paper-dim, #ece9e2); border-radius: 4px; }

.docgen-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 700px) { .docgen-grid2 { grid-template-columns: 1fr; } }

.docgen-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted-paper, #6b7078);
  margin-bottom: 5px;
}
.docgen-field input,
.docgen-field textarea,
.docgen-field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--paper-dim, #ece9e2);
  border-radius: var(--radius, 6px);
  font-family: var(--font-body);
  font-size: 14px;
}
.docgen-field textarea { min-height: 70px; resize: vertical; }

.docgen-meta-row { display: flex; flex-direction: column; gap: 12px; }

.docgen-table-wrap { overflow-x: auto; }
.docgen-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.docgen-table thead th {
  background: var(--ink-900, #1a1d23);
  color: #fff;
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 3px solid var(--ink-900, #1a1d23);
}
.docgen-table thead th.num { text-align: right; }
.docgen-table tbody td { padding: 6px; border-bottom: 1px solid var(--paper-dim, #ece9e2); vertical-align: middle; }
.docgen-table input { width: 100%; border: 1px solid transparent; padding: 8px; border-radius: 4px; font-size: 14px; }
.docgen-table input:focus { border-color: var(--accent, #ff6b35); outline: none; }
.docgen-table .item-qty, .docgen-table .item-rate { text-align: right; max-width: 100px; }
.docgen-table .item-amount { text-align: right; font-weight: 600; white-space: nowrap; padding-right: 12px; }
.docgen-table .item-remove {
  background: none; border: none; color: #c0392b; font-size: 18px; cursor: pointer; line-height: 1; padding: 4px 8px;
}
.docgen-table th:first-child, .docgen-table td:first-child { width: 42%; }
.docgen-table textarea.item-desc {
  width: 100%;
  border: 1px solid transparent;
  padding: 8px;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.55;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  min-height: 38px;
}
.docgen-table textarea.item-desc:focus { border-color: var(--accent, #ff6b35); outline: none; }

.docgen-addline {
  width: 100%;
  background: #f0efe9;
  border: none;
  border-top: 1px solid var(--paper-dim, #ece9e2);
  padding: 10px;
  font-size: 13.5px;
  cursor: pointer;
}
.docgen-addline:hover { background: var(--accent-dim, #ffe4d6); }

.docgen-zero-warning {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--accent-dim, #ffe4d6);
  border: 1px solid var(--accent, #ff6b35);
  border-radius: var(--radius, 6px);
  padding: 10px 14px;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.4;
}
.docgen-zero-warning span { flex: 1; min-width: 220px; }
.docgen-zero-warning #combineItemsBtn {
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid var(--accent, #ff6b35);
  border-radius: var(--radius, 6px);
  padding: 6px 12px;
}
@media print {
  .docgen-zero-warning { display: none !important; }
}

.docgen-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 28px;
  align-items: start;
}
@media (max-width: 700px) { .docgen-bottom-grid { grid-template-columns: 1fr; } }

.docgen-totals { display: flex; flex-direction: column; gap: 10px; }
.docgen-totals-row { display: flex; justify-content: space-between; font-size: 14px; }
.docgen-totals-row.hidden { display: none; }
.docgen-totals-row.grand { border-top: 1px solid var(--paper-dim, #ece9e2); padding-top: 10px; font-weight: 700; font-size: 17px; }
.docgen-inline-toggle { background: none; border: none; color: var(--accent, #ff6b35); font-size: 13px; cursor: pointer; padding: 0; text-align: left; }
.docgen-inline-input { display: flex; align-items: center; gap: 8px; }
.docgen-inline-input input { width: 70px; padding: 6px 8px; border: 1px solid var(--paper-dim, #ece9e2); border-radius: 4px; text-align: right; }

.docgen-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.docgen-btn-primary {
  background: var(--accent, #ff6b35); color: #fff; border: none; padding: 11px 22px;
  border-radius: var(--radius, 6px); font-weight: 700; font-size: 14px; cursor: pointer;
}
.docgen-btn-primary:hover { background: #e85a29; }
.docgen-btn-secondary { background: none; border: none; color: var(--accent, #ff6b35); font-size: 13.5px; cursor: pointer; padding: 0; }
.docgen-currency-select { width: auto; padding: 8px 10px; }

/* ---- GST invoice tool: make summary-table figures and CGST/SGST rows
   bold + full-contrast instead of the default light table text ---- */
.docgen-table input.item-hsn {
  border: 1px solid var(--paper-dim, #ece9e2) !important;
  border-radius: 4px;
}
.docgen-table input.item-hsn::placeholder {
  color: #b7bcc4;
}
/* ---- GST invoice tool: proper bordered invoice-grid look (matches
   standard Indian tax invoice formatting) instead of the plain
   borderless table used by the other document types ---- */
.gst-summary-table,
body.gst-invoice-print .docgen-table {
  border: 1px solid var(--ink-900, #1a1d23);
  border-collapse: collapse;
}
.gst-summary-table th,
.gst-summary-table td,
body.gst-invoice-print .docgen-table th,
body.gst-invoice-print .docgen-table td {
  border: 1px solid var(--paper-dim, #ece9e2);
}
body.gst-invoice-print #outAmountWords {
  border: 1px solid var(--paper-dim, #ece9e2);
  padding: 6px 10px;
  border-radius: 4px;
  background: #faf9f6;
}

.gst-summary-table td.item-amount {
  font-weight: 700;
  color: var(--text-on-paper, #23262e);
}
.gst-summary-table td.num {
  font-weight: 600;
  color: var(--text-on-paper, #23262e);
}
#outCgst, #outSgst, #outTax {
  font-weight: 700;
  color: var(--text-on-paper, #23262e);
}
#outAmountWords {
  color: var(--text-on-paper, #23262e) !important;
}

/* ---- Print / Download-as-PDF: hide everything except the doc panel ---- */
@media print {
  body * { visibility: hidden; }
  .docgen-panel, .docgen-panel * { visibility: visible; }
  .docgen-panel {
    position: absolute; left: 0; top: 0; width: 100%;
    border: none; padding: 0; box-shadow: none;
  }
  .docgen-table input, .docgen-field input, .docgen-field textarea {
    border: none !important; padding: 2px !important;
  }
  .docgen-table textarea.item-desc {
    border: none !important; padding: 2px !important; white-space: pre-wrap !important; overflow: visible !important;
  }
  .item-remove, .docgen-addline, .docgen-actions, .docgen-inline-toggle { display: none !important; }
  #f_logoFile, #removeLogoBtn { display: none !important; }
}
