/* ==========================================================================
   Shared Invoice Template - Print-Optimized Styles  (REDESIGN)
   Professional business document. Same class contract as the original;
   this is a restyle only — no DOM changes required.

   Design intent
   -------------
   1. Sleek & scannable — one consistent spacing rhythm (4/8/12/16/24),
      hairline rules, tabular numerals, calm neutrals.
   2. Professional & precise — crisp 90° corners, exact alignment, small-caps
      eyebrows, a tidy right-aligned meta grid (the old ragged 36px spacing is gone).
   3. Pertinent info leads the eye — the invoice Total is the hero at top AND
      bottom; the "Current Billed" contract column and the "Remaining" balance
      chips carry the most visual weight.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root {
    --inv-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Navy accent family (kept from house identity, tightened) */
    --inv-accent:        #2e4a72;   /* primary navy                */
    --inv-accent-deep:   #223a5e;   /* rules, hero, emphasis ink   */
    --inv-accent-light:  #5a739b;   /* secondary labels            */

    /* Ink & neutrals — cool bias toward the navy, chosen not defaulted */
    --inv-ink:          #1a2331;    /* headings / strong figures   */
    --inv-text-color:   #2b3644;    /* body                        */
    --inv-muted-color:  #66738a;    /* muted / secondary           */

    /* Structure */
    --inv-border-color:  #d3dae4;   /* standard hairline           */
    --inv-border-light:  #e7ebf1;   /* faint row divider           */

    /* Fills */
    --inv-panel:        #f6f8fb;    /* neutral panel / total rows  */
    --inv-accent-tint:  #eef2f8;    /* accent-tinted column / hero */

    /* Back-compat aliases (older markup/clients may reference these) */
    --inv-header-bg:       var(--inv-accent);
    --inv-header-color:    #ffffff;
    --inv-table-header-bg: #f4f6f9;
    --inv-total-bg:        var(--inv-panel);
    --inv-rule-color:      var(--inv-accent);
}

/* --------------------------------------------------------------------------
   Base container
   -------------------------------------------------------------------------- */
.inv-cover-page,
.inv-section,
.inv-final-total {
    font-family: var(--inv-font);
    font-size: 11px;
    line-height: 1.55;
    color: var(--inv-text-color);
    max-width: 8.5in;
    margin: 0 auto;
    -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
   Logo
   -------------------------------------------------------------------------- */
.inv-logo { margin-bottom: 14px; }

.inv-logo-img {
    max-height: 96px;
    max-width: 340px;
    object-fit: contain;
}

.inv-logo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 300px;
    height: 84px;
    border: 1px dashed var(--inv-border-color);
    color: var(--inv-muted-color);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* --------------------------------------------------------------------------
   Masthead
   -------------------------------------------------------------------------- */
.inv-cover-page {
    border-top: 3px solid var(--inv-accent-deep);   /* precise top rule */
    padding-top: 14px;
}

.inv-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;   /* INVOICE meta bottom-aligns with the left column (logo + remit + bill-to) */
    gap: 32px;
    margin-bottom: 14px;
}

/* Left column: logo + remit + bill-to stacked. Its height lets the INVOICE
   block on the right ride down beside the bill-to with no dead space. */
.inv-header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.inv-remit-to {
    font-size: 11px;
    line-height: 1.65;
    color: var(--inv-text-color);
}

.inv-company-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.2px;
    margin-bottom: 6px;
    color: var(--inv-ink);
}

.inv-remit-attn {
    font-size: 10px;
    color: var(--inv-muted-color);
    margin-top: 3px;
}

/* Right-hand meta block — bottom-aligned with the logo/address via the header row */
.inv-meta-box {
    text-align: right;
    min-width: 300px;
}

.inv-meta-title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 6px;
    text-transform: uppercase;
    color: var(--inv-accent);
    margin-bottom: 14px;
    line-height: 1;
}

/* Tidy aligned label/value grid (replaces the ragged border-spacing table) */
.inv-meta-table {
    margin-left: auto;
    border-collapse: collapse;
    border-spacing: 0;
}

.inv-meta-table td {
    font-size: 11px;
    white-space: nowrap;
    padding: 2px 0;
    vertical-align: baseline;
}

.inv-meta-label {
    text-align: right;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 9px;
    letter-spacing: 0.6px;
    color: var(--inv-muted-color);
    padding-right: 18px;
}

.inv-meta-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--inv-text-color);
    min-width: 130px;
}

/* Hero: the invoice total, drawn at the top-right */
.inv-meta-table tr:last-child .inv-meta-label,
.inv-meta-total {
    padding-top: 8px;
}
.inv-meta-table tr:last-child td {
    border-top: 1px solid var(--inv-border-color);
}
td.inv-meta-total {
    font-weight: 700;
    font-size: 20px;
    color: var(--inv-accent-deep);
    letter-spacing: 0.2px;
    min-width: 140px;
}

/* Bill-to — compact block (last item in the left column) */
.inv-bill-to {
    margin-bottom: 0;
    font-size: 11px;
    line-height: 1.35;
    padding: 5px 10px;
    background: var(--inv-panel);
    border-left: 3px solid var(--inv-accent);
    max-width: 300px;
}

.inv-bill-to-name {
    font-weight: 700;
    color: var(--inv-ink);
    margin-bottom: 1px;
}

/* Project info */
.inv-project-info {
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--inv-border-color);
}

.inv-project-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--inv-ink);
    margin-bottom: 4px;
}

.inv-description {
    font-size: 10px;
    color: var(--inv-muted-color);
    margin-bottom: 3px;
}

.inv-services-line {
    font-size: 10px;
    font-style: italic;
    color: var(--inv-muted-color);
}

/* --------------------------------------------------------------------------
   Section & sub-section headers  (small-caps eyebrows)
   -------------------------------------------------------------------------- */
.inv-section { margin-bottom: 26px; }

.inv-section-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.6px;
    color: var(--inv-accent-deep);
    padding: 0 0 6px 0;
    margin-bottom: 12px;
    border-bottom: 2px solid var(--inv-accent);
}

.inv-subsection-header {
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    color: var(--inv-accent-light);
    padding: 2px 0;
    margin-top: 12px;
    margin-bottom: 6px;
    margin-left: 20px;
}

/* --------------------------------------------------------------------------
   Group & parent headers
   -------------------------------------------------------------------------- */
.inv-parent-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--inv-accent-deep);
    padding: 6px 0 6px 10px;
    margin-top: 16px;
    margin-bottom: 6px;
    border-left: 2px solid var(--inv-accent-light);
}

.inv-group-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--inv-ink);
    padding: 7px 12px;
    margin-top: 22px;
    margin-bottom: 8px;
    background: var(--inv-panel);
    border-left: 3px solid var(--inv-accent);
}

.inv-indented      { padding-left: 24px !important; }
.inv-indented-deep { padding-left: 32px !important; }

.inv-group-subheader-row td { padding: 0; }
.inv-group-subheader-cell {
    font-size: 10px;
    font-weight: 700;
    color: var(--inv-ink);
    padding: 6px 0 2px 0 !important;
    border-bottom: 1px solid var(--inv-border-color) !important;
}

.inv-parent-row td { padding: 0; }
.inv-parent-cell {
    font-size: 11px;
    font-weight: 700;
    color: var(--inv-accent-deep);
    padding: 8px 0 4px 8px !important;
    border-bottom: none !important;
    border-left: 2px solid var(--inv-accent-light);
}

/* --------------------------------------------------------------------------
   Tables (shared)
   -------------------------------------------------------------------------- */
.inv-table {
    width: calc(100% - 20px);
    margin-left: 20px;
    border-collapse: collapse;
    table-layout: fixed;
    margin-bottom: 16px;
    font-size: 11px;
}

.inv-table th,
.inv-table td {
    padding: 4px 8px;
    word-wrap: break-word;
    vertical-align: top;
}

.inv-table thead th {
    font-size: 8.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    background: var(--inv-table-header-bg);
    color: var(--inv-muted-color);
    border-top: 1px solid var(--inv-border-light);
    border-bottom: 1px solid var(--inv-border-color);
    padding: 5px 8px;
}

.inv-th-left  { text-align: left; }
.inv-th-right { text-align: right; }

.inv-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.inv-table tbody tr + tr td { border-top: 1px solid var(--inv-border-light); }

/* Line-item description (first cell) reads a touch stronger than figures */
.inv-table tbody td:first-child { color: var(--inv-text-color); }

/* Total / subtotal rows */
.inv-subtotal-row td {
    font-weight: 600;
    border-top: 1px solid var(--inv-border-color);
    padding-top: 7px;
    white-space: nowrap;
    color: var(--inv-text-color);
}

.inv-total-row td {
    font-weight: 700;
    border-top: 1.5px solid var(--inv-accent);
    padding-top: 8px;
    padding-bottom: 8px;
    white-space: nowrap;
    color: var(--inv-ink);
    background: var(--inv-panel);
}

.inv-overhead-row td,
.inv-fee-row td {
    font-style: italic;
    color: var(--inv-muted-color);
    white-space: nowrap;
}

/* Shared last column (amount) width */
.inv-table th:last-child,
.inv-table td:last-child { width: 110px; }

/* --------------------------------------------------------------------------
   Contracts table  — the at-a-glance section.
   Emphasis lands on the final "Current Billed" column.
   Cols: Description | Contract | %Complete | Prior | Total | Current
   -------------------------------------------------------------------------- */
.inv-contracts-table th:first-child,
.inv-contracts-table td:first-child { width: auto; }

.inv-contracts-table th:nth-child(2),
.inv-contracts-table td:nth-child(2),
.inv-contracts-table th:nth-child(4),
.inv-contracts-table td:nth-child(4),
.inv-contracts-table th:nth-child(5),
.inv-contracts-table td:nth-child(5) { width: 88px; }

.inv-contracts-table th:nth-child(3),
.inv-contracts-table td:nth-child(3) { width: 66px; }

/* Emphasized "Current Billed" column (last) */
.inv-contracts-table th:last-child {
    color: var(--inv-accent-deep);
    background: var(--inv-accent-tint);
}
.inv-contracts-table tbody td:last-child {
    font-weight: 700;
    color: var(--inv-accent-deep);
    background: var(--inv-accent-tint);
}
.inv-contracts-table tfoot .inv-total-row td:last-child {
    font-size: 12.5px;
    color: var(--inv-accent-deep);
    background: var(--inv-accent-tint);
}
.inv-contracts-table tfoot .inv-total-row td:first-child {
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-size: 10px;
}

/* --------------------------------------------------------------------------
   Labor / Expense / Backup column widths (unchanged geometry)
   -------------------------------------------------------------------------- */
.inv-labor-table th:nth-child(1),
.inv-labor-table td:nth-child(1) { width: 22%; }
.inv-labor-table th:nth-child(2),
.inv-labor-table td:nth-child(2) { width: auto; }
.inv-labor-table th:nth-child(3),
.inv-labor-table td:nth-child(3) { width: 10%; }
.inv-labor-table th:nth-child(4),
.inv-labor-table td:nth-child(4) { width: 110px; }

.inv-expense-table th:first-child,
.inv-expense-table td:first-child { width: auto; }

.inv-backup-table th:nth-child(1),
.inv-backup-table td:nth-child(1) { width: 18%; }
.inv-backup-table th:nth-child(2),
.inv-backup-table td:nth-child(2) { width: auto; }

/* Charge backup (Reimbursable Expenses / Outside Consultants):
   Item | [Comments] | Date | Qty | Each | MU | Total
   Qty / Each / MU are tiny numeric columns — size them from the RIGHT so the
   widths hold whether or not the optional Comments column is present, and give
   all the reclaimed room to Item + Comments. */
.inv-backup-charge td:first-child,
.inv-backup-charge th:first-child { width: auto; }                 /* Item — flexible */
.inv-backup-charge td:last-child,
.inv-backup-charge th:last-child { width: 84px; }                  /* Total */
.inv-backup-charge td:nth-last-child(2),
.inv-backup-charge th:nth-last-child(2) { width: 38px; }           /* MU (3 digits, e.g. 1.15) */
.inv-backup-charge td:nth-last-child(3),
.inv-backup-charge th:nth-last-child(3) { width: 62px; }           /* Each */
.inv-backup-charge td:nth-last-child(4),
.inv-backup-charge th:nth-last-child(4) { width: 44px; }           /* Qty */
.inv-backup-charge td:nth-last-child(5),
.inv-backup-charge th:nth-last-child(5) { width: 80px; white-space: nowrap; }  /* Date (MM/DD/YYYY) — headroom so it never wraps */

/* Labor backup: [Job Title] | Employee | [Comments] | Date | Hours | Rate | Total
   Employee + Comments get the room; Date / Hours / Rate stay compact. Sized from
   the right so it holds regardless of the optional Job Title / Comments columns. */
.inv-backup-labor td:first-child,
.inv-backup-labor th:first-child { width: auto; }                 /* Employee (or Job Title) */
.inv-backup-labor td:last-child,
.inv-backup-labor th:last-child { width: 84px; }                  /* Total */
.inv-backup-labor td:nth-last-child(2),
.inv-backup-labor th:nth-last-child(2) { width: 68px; }           /* Rate */
.inv-backup-labor td:nth-last-child(3),
.inv-backup-labor th:nth-last-child(3) { width: 50px; }           /* Hours */
.inv-backup-labor td:nth-last-child(4),
.inv-backup-labor th:nth-last-child(4) { width: 80px; white-space: nowrap; }   /* Date (MM/DD/YYYY) — headroom so it never wraps */

.inv-comments {
    font-size: 9px;
    color: var(--inv-muted-color);
}

/* --------------------------------------------------------------------------
   Contract summary (NE / CC) — compact horizontal chip strip.
   4 chips in fixed order: Contract | Previous | Current | Remaining.
   "Current" and (especially) "Remaining" carry the weight.
   -------------------------------------------------------------------------- */
.inv-contract-summary {
    display: flex;
    gap: 0;
    margin: 6px 0 12px 20px;
    max-width: 480px;
    border: 1px solid var(--inv-border-color);
    background: #fff;
}

.inv-contract-line {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 12px;
    border-left: 1px solid var(--inv-border-light);
}
.inv-contract-line:first-child { border-left: none; }

.inv-contract-label {
    font-size: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--inv-muted-color);
}

.inv-contract-value {
    font-weight: 700;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--inv-text-color);
    text-align: left;
}

/* Current Billed (3rd) — the amount being invoiced now carries the weight */
.inv-contract-line:nth-child(3) .inv-contract-value { color: var(--inv-accent-deep); }

/* --------------------------------------------------------------------------
   Phase total  — clear scan line per phase
   -------------------------------------------------------------------------- */
.inv-phase-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 7px 8px;
    margin: 10px 0 22px 0;
    border-top: 1.5px solid var(--inv-accent);
    font-weight: 700;
    font-size: 11px;
    color: var(--inv-ink);
}

.inv-phase-total-label { text-transform: none; }
.inv-phase-total-amount {
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
    color: var(--inv-accent-deep);
}

/* Grand total (transaction details) */
.inv-grand-total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    margin-top: 10px;
    border-top: 2px solid var(--inv-accent);
    font-weight: 700;
    font-size: 11px;
    color: var(--inv-ink);
}
.inv-grand-total-amount { font-variant-numeric: tabular-nums; }

/* Tax table */
.inv-tax-table th:first-child,
.inv-tax-table td:first-child { width: 40%; }

/* --------------------------------------------------------------------------
   Invoice total (final)  — the hero "amount due" bar
   -------------------------------------------------------------------------- */
.inv-final-total {
    margin-top: 34px;
    padding-top: 0;
}

.inv-final-rule {
    height: 3px;
    background: var(--inv-accent-deep);
    margin-bottom: 0;
}

.inv-final-amount-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 14px 16px;
    background: var(--inv-accent-tint);
    border-bottom: 1px solid var(--inv-border-color);
}

.inv-final-label {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--inv-accent-deep);
}

.inv-final-amount {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--inv-accent-deep);
    letter-spacing: 0.2px;
}

/* --------------------------------------------------------------------------
   Statement (AR aging)
   -------------------------------------------------------------------------- */
.inv-statement {
    font-family: var(--inv-font);
    font-size: 11px;
    line-height: 1.5;
    color: var(--inv-text-color);
    max-width: 8.5in;
    margin-top: 34px;
}

.inv-statement .inv-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--inv-accent-deep);
    border-bottom: 2px solid var(--inv-accent);
    padding-bottom: 6px;
    margin-bottom: 10px;
}

.inv-statement-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 11px;
}

.inv-statement-table thead th {
    font-size: 8.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--inv-muted-color);
    border-bottom: 1px solid var(--inv-border-color);
    padding: 4px 8px;
    text-align: right;
}

.inv-stmt-col-invoice { text-align: left !important; width: 18%; }
.inv-stmt-col-date    { text-align: left !important; width: 12%; }
.inv-stmt-col-age     { width: 13%; }
.inv-stmt-col-balance { width: 14%; }

.inv-stmt-invno { padding-left: 12px; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--inv-ink); }
.inv-stmt-date  { font-variant-numeric: tabular-nums; color: var(--inv-muted-color); }
.inv-stmt-label { padding-left: 24px; font-size: 10px; color: var(--inv-muted-color); }

.inv-stmt-amount { text-align: right; font-variant-numeric: tabular-nums; padding: 3px 8px; }

.inv-stmt-invoice-row td { padding-top: 6px; padding-bottom: 1px; }
.inv-stmt-detail-row  td { padding-top: 1px; padding-bottom: 4px; }

.inv-stmt-total-row td {
    font-weight: 700;
    border-top: 1.5px solid var(--inv-accent);
    padding-top: 6px;
    color: var(--inv-ink);
    background: var(--inv-panel);
}
.inv-stmt-total-label { padding-left: 12px; }

/* --------------------------------------------------------------------------
   Page breaks — the invoice body flows continuously (no forced section /
   Backup / Statement breaks). The only page break is before the attachments,
   which pdf-lib appends as their own pages, so no CSS is needed for it.
   -------------------------------------------------------------------------- */
.inv-page-break { page-break-before: auto; }

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */
@page {
    size: letter;
    margin: 0.75in 0.75in 1in 0.75in;
}

@media print {
    .inv-cover-page,
    .inv-section,
    .inv-final-total { max-width: 100%; }

    /* Body flows continuously — no forced or section-level page breaks. */
    .page-break-before { page-break-before: auto; }

    .inv-table { page-break-inside: auto; }
    .inv-table tr { page-break-inside: avoid; }
    .inv-table thead { display: table-header-group; }

    /* Keep tinted emphasis in the printed PDF */
    .inv-section-header,
    .inv-parent-header,
    .inv-group-header,
    .inv-total-row td,
    .inv-contracts-table th:last-child,
    .inv-contracts-table tbody td:last-child,
    .inv-contracts-table tfoot .inv-total-row td:last-child,
    .inv-contract-line:last-child,
    .inv-final-amount-row,
    .inv-final-rule,
    .inv-stmt-total-row td,
    .inv-bill-to {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .inv-print-header {
        position: fixed;
        top: 0; left: 0; right: 0;
        display: flex;
        justify-content: space-between;
        font-size: 8px;
        color: var(--inv-muted-color);
        padding: 4px 0;
        border-bottom: 1px solid var(--inv-border-color);
    }

    .inv-print-footer {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        border-top: 1px solid var(--inv-accent);
        padding-top: 4px;
        text-align: right;
        font-size: 8px;
        color: var(--inv-muted-color);
    }
}
