html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

body {
  margin-bottom: 60px;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

.tax-invoice-page {
  background: #fff;
  max-width: 210mm;
  margin: 0 auto;
  font-size: 0.9rem;
  color: #000;
}

.tax-invoice-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 0;
}

.tax-invoice-table + .tax-invoice-table,
.tax-lines-table + .js-invoice-closing > .tax-invoice-table {
  margin-top: -1px;
}

.invoice-signatory {
  margin-top: 10mm;
  margin-left: 0;
  width: 50mm;
  max-width: 55mm;
  text-align: center;
}

.invoice-signatory-image {
  display: block;
  max-height: 18mm;
  max-width: 50mm;
  margin: 0 auto 1mm;
  object-fit: contain;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.invoice-signatory-line {
  border-bottom: 1px dotted #000;
  width: 100%;
  margin: 0 0 1.5mm 0;
}

.invoice-signatory-caption,
.invoice-signatory-company {
  font-size: 0.85rem;
  line-height: 1.35;
}

.invoice-signatory-company {
  font-weight: 600;
}

.tax-invoice-table th,
.tax-invoice-table td {
  border: 1px solid #000;
  padding: 0.35rem 0.5rem;
  vertical-align: top;
  overflow-wrap: break-word;
  word-break: break-word;
}

.tax-invoice-table th {
  font-weight: 700;
  text-align: center;
}

/* Line items keep column rules; open body rows use padding instead of horizontal lines. */
.tax-lines-table tbody td {
  border-top: none;
  border-bottom: none;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

/* Filler closes the grid on continuation pages (no tfoot) and under the last items. */
.tax-lines-table tbody .tax-filler-row td {
  border-bottom: 1px solid #000;
  padding-top: 0;
  padding-bottom: 0;
}

.tax-lines-table thead th {
  border-bottom: 1px solid #000;
}

.tax-lines-table tfoot td {
  border: 1px solid #000;
}

.tax-title {
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.5rem;
}

.tax-field,
.tax-party-cell {
  min-height: 2rem;
}

.tax-party-cell {
  height: 7rem;
}

.tax-party-line {
  margin-bottom: 0.35rem;
}

.tax-label {
  font-weight: 600;
  white-space: nowrap;
}

.tax-value {
  margin-left: 0.25rem;
}

.tax-col-left { width: 50%; }
.tax-col-right { width: 50%; }
.tax-col-ref { width: 14%; }
.tax-col-desc { width: 36%; }
.tax-col-qty { width: 12%; }
.tax-col-price { width: 18%; }
.tax-col-amount { width: 20%; }

.tax-summary-row td {
  font-weight: 600;
}

.tax-summary-label {
  text-align: left;
}

.invoice-logo {
  max-height: 72px;
  max-width: 220px;
}

.invoice-logo-placeholder {
  width: 120px;
  height: 72px;
  border: 1px dashed #adb5bd;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c757d;
  font-size: 0.875rem;
}

/* Sheets are generated by invoice-print.js and only ever shown on paper. */
.invoice-sheets {
  display: none;
}

/* The one place sheet geometry and print typography are declared. The printed
   sheets and the offscreen measuring rig in invoice-print.js both derive from
   these, so what the paginator measures cannot drift from what gets drawn.
   Height sits a shade under A4 as headroom: Chrome resolves 297mm to a fractional
   pixel count, and a sheet sized to the page box exactly can round over it. */
:root {
  --invoice-print-font-size: 10pt;
  --invoice-sheet-width: 210mm;
  --invoice-sheet-height: 296.5mm;
  --invoice-sheet-padding: 12mm;
}

.invoice-print-metrics,
.invoice-print-metrics .tax-invoice-page {
  font-size: var(--invoice-print-font-size);
  max-width: none;
  margin: 0;
  padding: 0;
  color: #000;
  background: #fff;
}

/* Declared outside the print block so the rig can measure the footer band. */
.sheet-foot {
  padding-top: 2mm;
  text-align: center;
  font-size: 8pt;
  color: #000;
}

/* The page margin lives on the sheet as padding instead, otherwise a table at the
   full printable width has its collapsed outer border painted half off the paper
   and the right edge prints faint or not at all. */
@page {
  size: A4 portrait;
  margin: 0;
}

.legal-page {
  max-width: 48rem;
  margin: 0 auto;
}

.legal-page-header h1 {
  font-weight: 600;
}

.legal-page-body h2 {
  font-weight: 600;
  margin-top: 0.5rem;
}

.legal-page-body h3 {
  font-weight: 600;
}

.legal-page-body p,
.legal-page-body li {
  line-height: 1.65;
}

.legal-page-body ul {
  padding-left: 1.25rem;
}

.legal-page-body address {
  font-style: normal;
  line-height: 1.65;
}

@media print {
  html,
  body {
    margin: 0;
    padding: 0;
    width: auto;
    background: #fff;
  }

  header,
  footer,
  .d-print-none {
    display: none !important;
  }

  /* !important is required here: the layout puts Bootstrap spacing utilities on
     this wrapper (pb-3), and those carry !important themselves. Any padding left
     below the sheet spills past the page box and prints a trailing blank page. */
  .container {
    width: auto;
    max-width: none;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* The flowing markup is the on-screen view and the paginator's source. It is
     only safe to hide once invoice-print.js has actually produced sheets, which
     is what the marker class signals - otherwise a script failure would print a
     blank page instead of an unpaginated invoice. */
  .invoice-paginated #invoiceScreen {
    display: none !important;
  }

  .invoice-sheets {
    display: block;
  }

  /* Fallback path only: with no sheets to print, the browser paginates the source
     markup itself and these keep the result legible. The padding stands in for the
     page margin, which the sheets normally carry. */
  #invoiceScreen {
    margin: 0;
    padding: var(--invoice-sheet-padding);
    width: auto;
    max-width: none;
    font-size: var(--invoice-print-font-size);
  }

  .tax-lines-table thead {
    display: table-header-group;
  }

  .tax-invoice-table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .invoice-sheet {
    width: var(--invoice-sheet-width);
    height: var(--invoice-sheet-height);
    padding: var(--invoice-sheet-padding);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: var(--invoice-print-font-size);
    color: #000;
  }

  /* break-before on later sheets rather than break-after on every sheet, which
     would emit a trailing blank page. */
  .invoice-sheet + .invoice-sheet {
    page-break-before: always;
    break-before: page;
  }

  /* Meta, closing (incl. signature), and page footer must not shrink when the
     lines table absorbs remaining height on multi-page sheets. */
  .sheet-head,
  .sheet-close,
  .sheet-foot {
    flex: 0 0 auto;
  }

  .sheet-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .sheet-body > .tax-invoice-table {
    flex: 1 1 auto;
  }

  /* Restores the shared border between bands now that they sit in separate boxes. */
  .sheet-head + .sheet-body > .tax-invoice-table,
  .sheet-body + .sheet-close > .tax-invoice-table,
  .sheet-body + .sheet-close .js-invoice-closing > .tax-invoice-table {
    margin-top: -1px;
  }

  /* 1px reads as "shrink to content", leaving the filler row to absorb the slack
     so the ruled grid reaches the bottom of the sheet however few lines there are. */
  .invoice-sheet .tax-lines-table tr {
    height: 1px;
  }

  .invoice-sheet .tax-lines-table .tax-filler-row {
    height: auto;
  }

  .tax-invoice-table th,
  .tax-invoice-table td {
    border: 1px solid #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .tax-lines-table tbody td {
    border-top: none !important;
    border-bottom: none !important;
  }

  .tax-lines-table tbody .tax-filler-row td {
    border-bottom: 1px solid #000 !important;
    padding-top: 0;
    padding-bottom: 0;
  }
}