/* Shared document typography. Scoped so invoices cannot restyle the surrounding app. */
.invoice-sheet {
    max-width: 800px;
    margin: 1rem auto;
    padding: 32px;
    box-sizing: border-box;
    position: relative;
    background: #fff;
    border: 1px solid #e3e8ef;
    color: #243247;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    font-size: 13px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
}

.invoice-sheet .small { font-size: 11.5px; }
.invoice-sheet .text-muted,
.invoice-sheet .k,
.invoice-sheet .printed-label { color: #5b6777 !important; }
.invoice-sheet .v,
.invoice-sheet .printed-time { font-weight: 600; }
.invoice-sheet .printed-label { margin-inline-end: 4px; }
.invoice-sheet .printed-left { text-align: left; direction: ltr; }

.invoice-sheet .inv-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}
.invoice-sheet .inv-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.invoice-sheet .inv-logo { max-height: 48px; max-width: 140px; object-fit: contain; flex-shrink: 0; }
.invoice-sheet .inv-company { margin: 0; font-size: 20px; font-weight: 700; color: #18335c; line-height: 1.3; overflow-wrap: anywhere; }
.invoice-sheet .inv-doc-title { font-size: 16px; font-weight: 700; text-align: end; line-height: 1.35; }
.invoice-sheet .inv-head > .inv-doc-title,
.invoice-sheet .inv-head > .text-end { flex-shrink: 0; max-width: 38%; }
.invoice-sheet .inv-vat { margin-top: 4px; font-size: 11.5px; }

.invoice-sheet .inv-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 24px;
    padding: 8px 0;
    border-block: 1px solid #dce3ec;
    margin-bottom: 14px;
    font-size: 12px;
}
.client-invoice-sheet .inv-meta { column-gap: 20px; justify-content: space-between; }
.invoice-sheet .inv-info {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 20px;
    padding: 10px 0;
    border-block: 1px solid #dce3ec;
    font-size: 12px;
    direction: ltr;
}
.invoice-sheet .inv-info .k,
.invoice-sheet .inv-info .v { unicode-bidi: isolate; }
.invoice-sheet .inv-info .inv-info-wide { grid-column: span 2; }

.invoice-sheet .party { border: 1px solid #d6dfe9; border-radius: 5px; margin-bottom: 12px; overflow: hidden; }
.invoice-sheet .party-head { background: #f0f3f7; font-size: 13px; font-weight: 600; padding: 7px 12px; border-bottom: 1px solid #d6dfe9; }
.invoice-sheet .party-body { display: flex; flex-wrap: wrap; }
.invoice-sheet .party-body .field { flex: 1 1 40%; min-width: 0; padding: 7px 12px; border-top: 1px solid #edf0f4; }
.invoice-sheet .party-body .field-wide { flex-basis: 100%; }
.invoice-sheet .party-body .field .k { font-size: 11.5px; margin-bottom: 2px; }
.invoice-sheet .party-body .field .v { font-size: 13px; font-weight: 400; overflow-wrap: anywhere; unicode-bidi: plaintext; text-align: left; }
.invoice-sheet:dir(rtl) .party-body .field .v { text-align: right; }

/* Keep the client's identifiers in the same physical columns in both UI languages. */
.client-invoice-sheet .buyer-fields { display: grid; grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)); }
.client-invoice-sheet .buyer-name { grid-column: 1; }
.client-invoice-sheet .buyer-cr { grid-column: 2; }
.client-invoice-sheet .buyer-vat { grid-column: 3; }
.client-invoice-sheet .buyer-fields .field-wide { grid-column: 1 / -1; }
.client-invoice-sheet:dir(rtl) .buyer-fields .field .v { text-align: left; }

.invoice-sheet table { width: 100%; border-collapse: collapse; font-size: 12px; line-height: 1.4; }
.invoice-sheet th,
.invoice-sheet td { padding: 6px; border-bottom: 1px solid #e3e8ef; vertical-align: top; }
.invoice-sheet th { background: #f0f3f7; text-align: start; font-size: 11px; font-weight: 600; line-height: 1.35; vertical-align: bottom; }
.invoice-sheet .text-end { text-align: right !important; }
.invoice-sheet td.text-end { white-space: nowrap; direction: ltr; }
.invoice-sheet .inv-items { margin: 14px 0 12px; }
.invoice-sheet .inv-items th:first-child { width: 28%; }
.invoice-sheet .inv-items td:first-child { overflow-wrap: anywhere; }
.invoice-sheet .inv-items th { border-top: 1px solid #c6d1df; border-bottom: 1px solid #c6d1df; }
.invoice-sheet .inv-items tbody tr:last-child td { border-bottom: 1px solid #c6d1df; }
.invoice-sheet .order-subtotal td { background: #f8f9fb; }
.invoice-sheet.credit-note-sheet .inv-items .inv-code { width: 12%; overflow-wrap: anywhere; }
.credit-note-sheet .inv-items .inv-description { width: 28%; overflow-wrap: anywhere; }
.invoice-sheet .order-heading { background: #f0f3f7; font-size: 13px; font-weight: 600; padding: 8px 10px; margin-top: 14px; border-inline-start: 3px solid #18335c; break-after: avoid; }

.invoice-sheet .inv-summary { display: grid; grid-template-columns: minmax(100px, 1fr) minmax(0, 2fr); align-items: start; gap: 20px; margin-top: 14px; }
.invoice-sheet .inv-summary > * { min-width: 0; }
.credit-note-sheet .inv-summary { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.invoice-sheet .inv-qr { width: 100px; height: 100px; display: block; }
.invoice-sheet .inv-totals td { padding: 5px 6px; }
.invoice-sheet .inv-totals .bilabel,
.invoice-sheet .inv-totals .bilabel-en,
.invoice-sheet .inv-totals .bilabel-ar { display: inline; }
.invoice-sheet .inv-totals .bilabel-en:not(:last-child)::after { content: " / "; }
.invoice-sheet .inv-totals td:first-child { direction: ltr; text-align: left; }
.credit-note-sheet .inv-totals td:first-child { direction: inherit; text-align: start; }
.invoice-sheet .inv-totals td:last-child { width: 1%; padding-inline-start: 14px; }
.invoice-sheet .inv-totals .grand td { padding-block: 8px; border-top: 1px solid #b9c7d8; border-bottom: 2px solid #18335c; background: #f4f6f9; font-size: 14px; font-weight: 700; color: #18335c; }
.invoice-sheet .inv-footer { margin-top: 16px; padding-top: 8px; text-align: center; font-size: 11.5px; color: #5b6777; }
.invoice-sheet .inv-footer-address { border-top: 1px solid #dce3ec; margin-top: 8px; padding-top: 8px; }

/* The patient document keeps its established full A4 sheet and bottom footer. */
.patient-invoice-sheet { width: 210mm; max-width: 100%; min-height: 297mm; padding: 12mm 14mm 6mm; display: flex; flex-direction: column; }
.patient-invoice-sheet .inv-footer { margin-top: auto; padding-top: 16px; }

@media screen and (max-width: 600px) {
    .invoice-sheet { padding: 18px; }
    .invoice-sheet .inv-head { flex-wrap: wrap; gap: 10px; }
    .invoice-sheet .inv-head > .inv-doc-title,
    .invoice-sheet .inv-head > .text-end { max-width: 100%; }
    .invoice-sheet .inv-info { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .invoice-sheet .party-body .field { flex-basis: 100%; }
    .client-invoice-sheet .buyer-fields { grid-template-columns: minmax(0, 1fr); }
    .client-invoice-sheet .buyer-fields .field { grid-column: 1; }
    .invoice-sheet .inv-summary { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .invoice-sheet .inv-items { display: block; overflow-x: auto; }
    .invoice-sheet .inv-items th { min-width: 64px; }
    .invoice-sheet .inv-items th:first-child { min-width: 160px; }
    .credit-note-sheet .inv-items th.inv-code { min-width: 64px; }
    .credit-note-sheet .inv-items th.inv-description { min-width: 160px; }
}

@media print {
    .invoice-sheet { box-shadow: none !important; border: none !important; margin: 0 auto !important; padding: 12mm 14mm !important; max-width: none !important; width: 100%; }
    .patient-invoice-sheet { width: 210mm; min-height: 290mm; padding-bottom: 6mm !important; }
    .invoice-sheet tr,
    .invoice-sheet .party,
    .invoice-sheet .inv-summary { break-inside: avoid; }
    .invoice-sheet thead { display: table-header-group; }
    .invoice-sheet .inv-head { break-inside: avoid; }
    .invoice-sheet th,
    .invoice-sheet .party-head,
    .invoice-sheet .grand td { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
