/*
 * Billing group print layout — loaded only by layouts/billing_print.html.erb
 */

:root {
  --ink: #1a1f2b;
  --ink-muted: #5a6473;
  --ink-faint: #8a93a3;
  --line: #d6d9df;
  --line-light: #e6e8ec;
  --surface: #ffffff;
  --surface-muted: #fafbfc;
  --accent: #137a4a;
  --accent-dark: #0f6239;
  --accent-soft: #e8f5ec;
  --accent-soft-strong: #d4edda;
  --accent-border: #b8dfc8;
  --accent-border-strong: #9fd4b4;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 14px;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Inter, system-ui, sans-serif;
  color: var(--ink);
  line-height: 1.45;
  background: #eef1f5;
}

.no-print {
  display: block;
}

.print-toolbar {
  max-width: 14in;
  margin: 16px auto 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--ink-muted);
}

.print-toolbar__actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.print-toolbar__btn {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}

.print-toolbar__btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.sheet {
  background: var(--surface);
  box-shadow: 0 2px 24px rgba(26, 31, 43, 0.12);
  margin: 0 auto 24px;
}

.sheet--summary {
  max-width: 8.5in;
  padding: 0.55in 0.6in 0.65in;
  /* Screen-only letter-page preview height. Flex + overflow:hidden on
     .table-wrap both prevent print fragmentation and push a tall summary
     table to page 2 (blank first page after the header). Print overrides below. */
  min-height: 11in;
}

.sheet--detail {
  max-width: 14in;
  padding: 0.25in;
}

.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.summary-header__brand img {
  height: 36px;
  width: auto;
}

.summary-header__meta {
  text-align: right;
  font-size: 13px;
  color: var(--ink);
  line-height: 1.55;
}

.summary-header__title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 2px;
}

.summary-table-heading {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.detail-head {
  margin-bottom: 6px;
}

.detail-head h2 {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 700;
}

.detail-head p {
  margin: 0;
  font-size: 9px;
  color: var(--ink-muted);
}

.table-wrap {
  overflow: hidden;
}

table.summary-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 10pt;
}

/* Prefer room for large $ amounts; community names wrap. */
table.summary-table col.col-community {
  width: 22%;
}

table.summary-table col.col-num {
  width: 19.5%;
}

table.summary-table thead th {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
  padding: 6px 6px;
  vertical-align: bottom;
  font-size: 8pt;
  font-weight: 700;
  color: var(--ink-muted);
  line-height: 1.2;
}

table.summary-table thead th span {
  display: block;
}

table.summary-table thead th.num,
table.summary-table tbody td.num {
  text-align: right;
  white-space: nowrap;
}

table.summary-table .group-start {
  border-left: 1px solid var(--ink-muted);
}

table.summary-table .group-end {
  border-right: 1px solid var(--ink-muted);
}

table.summary-table tbody td {
  border-bottom: 1px solid var(--line-light);
  padding: 8px 6px;
  vertical-align: top;
  line-height: 1.35;
  color: var(--ink);
}

table.summary-table tbody td.text-wrap {
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
  word-break: break-word;
  hyphens: auto;
}

table.summary-table tr.summary-total-row td {
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  padding: 10px 6px;
  font-weight: 700;
}

table.detail-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 6.75pt;
}

/* Identity cols are secondary to $ groups. Job # sized for typical lengths
   (median ~10); only rare max-length values (up to 39) truncate.
   Closing keeps full M/D/YYYY with room to show most of the year. */
table.detail-table col.col-id {
  width: 10%;
}

table.detail-table col.col-address {
  width: 7%;
}

table.detail-table col.col-account {
  width: 8%;
}

table.detail-table col.col-type {
  width: 2%;
}

table.detail-table col.col-closing {
  width: 4.5%;
}

table.detail-table col.col-num {
  width: 5.708%;
}

table.detail-table thead th {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
  padding: 2px 2px;
  vertical-align: bottom;
  font-size: 6pt;
  font-weight: 700;
  color: var(--ink-muted);
  line-height: 1.1;
}

table.detail-table thead tr.detail-group-row th {
  text-align: center;
  vertical-align: middle;
  font-size: 6.5pt;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

table.detail-table thead tr.detail-group-row th.group-label {
  background: var(--surface-muted);
}

table.detail-table thead th span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.detail-table thead th.num,
table.detail-table tbody td.num {
  text-align: right;
}

table.detail-table .group-start {
  border-left: 1px solid var(--ink-muted);
}

table.detail-table .group-end {
  border-right: 1px solid var(--ink-muted);
}

table.detail-table tbody td {
  border-bottom: 1px solid var(--line-light);
  padding: 1px 2px;
  vertical-align: top;
  line-height: 1.1;
}

tr.community-row td,
tr.grand-total-row td {
  background: var(--accent-soft);
  border-top: 1px solid var(--accent-border);
  border-bottom: 1px solid var(--accent-border);
  padding: 3px 4px;
  font-size: 6.5pt;
  font-weight: 600;
  color: var(--accent-dark);
}

tr.grand-total-row td {
  background: var(--accent-soft-strong);
  border-top: 1px solid var(--accent-border-strong);
  border-bottom: 1px solid var(--accent-border-strong);
}

tr.community-row td.group-start,
tr.grand-total-row td.group-start {
  border-left: 1px solid var(--ink-muted);
}

tr.community-row td.group-end,
tr.grand-total-row td.group-end {
  border-right: 1px solid var(--ink-muted);
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.text {
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.text-wrap {
  white-space: normal;
  word-break: break-word;
}

td.muted {
  color: var(--ink-faint);
}

@page summary {
  /* Keep CSS page margins modest — Chrome "Default" uses these. Large
     margins shrink the first fragment so a long table may be deferred. */
  size: letter portrait;
  margin: 0.5in;
}

@page detail {
  size: legal landscape;
  margin: 0.25in;
}

.print-summary {
  page: summary;
}

.print-detail {
  page: detail;
  page-break-before: always;
}

@media print {
  body {
    background: white;
  }

  .no-print {
    display: none !important;
  }

  .sheet {
    max-width: none;
    margin: 0;
    padding: 0;
    box-shadow: none;
  }

  thead {
    display: table-header-group;
  }

  .sheet--summary {
    min-height: 0 !important;
    height: auto !important;
  }

  /* overflow:hidden creates a non-fragmentable box in print engines. */
  .sheet--summary .table-wrap {
    overflow: visible !important;
    break-inside: auto;
    page-break-inside: auto;
  }

  table.summary-table {
    break-inside: auto;
    page-break-inside: auto;
  }

  .sheet--detail {
    font-size: 6.75pt;
  }

  table.detail-table tbody tr {
    break-inside: avoid;
  }

  /* Detail only: keep a community subtotal with the rows that follow.
     Do NOT set break-after:avoid on summary rows — that forces the whole
     summary table onto the next page (blank first page under the title). */
  tr.community-row,
  tr.grand-total-row {
    break-after: avoid;
  }

  table.summary-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: auto;
    page-break-after: auto;
  }

  table.detail-table tr {
    break-inside: avoid;
  }
}
