:root {
    color-scheme: light;
    --bg: #f5f7f6;
    --surface: #ffffff;
    --surface-soft: #edf3ef;
    --line: #d7ded9;
    --line-strong: #aebbb3;
    --text: #17211b;
    --muted: #627068;
    --accent: #1d6f5d;
    --accent-strong: #155144;
    --accent-soft: #dcefe9;
    --warn: #b26a00;
    --danger: #b43b3b;
    --ok: #1f7a4d;
    --shadow: 0 12px 28px rgba(23, 33, 27, 0.08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-variant-numeric: tabular-nums;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.tabs a {
    min-height: 36px;
}

button {
    border: 0;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    padding: 8px 14px;
    white-space: nowrap;
}

button:hover {
    background: var(--accent-strong);
}

button.secondary {
    background: var(--surface-soft);
    color: var(--accent-strong);
    border: 1px solid var(--line);
}

.button-link {
    align-items: center;
    border-radius: 7px;
    display: inline-flex;
    font-weight: 700;
    min-height: 36px;
    padding: 8px 14px;
    text-decoration: none;
    white-space: nowrap;
}

.button-link.secondary {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    color: var(--accent-strong);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    padding: 7px 9px;
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

label input,
label select,
label textarea {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

input[readonly] {
    background: #f2f5f3;
    color: var(--muted);
}

.token-display {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    overflow-x: auto;
}

.inline-check {
    align-items: center;
    display: flex;
    gap: 8px;
}

.inline-check input {
    width: 18px;
    height: 18px;
}

.app-shell {
    width: 100%;
    max-width: none;
    padding: 18px 16px 42px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 240px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    font-weight: 800;
}

.brand strong,
.brand span {
    display: block;
}

.brand strong {
    font-size: 19px;
    letter-spacing: 0;
}

.brand div span {
    color: var(--muted);
    font-size: 13px;
}

.context-switcher,
.unit-picker {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: 10px;
}

.context-switcher label {
    min-width: 170px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow: visible;
    border-bottom: 1px solid var(--line);
    margin-bottom: 18px;
    padding-bottom: 8px;
}

.tabs a,
.tabs-dropdown summary {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--muted);
    font-weight: 800;
    padding: 7px 12px;
    text-decoration: none;
    white-space: nowrap;
}

.tabs-dropdown {
    position: relative;
}

.tabs-dropdown summary {
    cursor: pointer;
    list-style: none;
}

.tabs-dropdown summary::-webkit-details-marker {
    display: none;
}

.tabs-dropdown summary::after {
    content: "v";
    font-size: 12px;
    margin-left: 7px;
}

.tabs-dropdown div {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 4px;
    min-width: 160px;
    padding: 6px;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 30;
}

.tabs-dropdown:not([open]) div {
    display: none;
}

.tabs-dropdown div a {
    justify-content: flex-start;
}

.tabs a.active,
.tabs a:hover,
.tabs-dropdown summary.active,
.tabs-dropdown summary:hover {
    background: var(--accent-soft);
    border-color: #b7d8cf;
    color: var(--accent-strong);
}

.notice {
    border: 1px solid #bad5ca;
    border-radius: var(--radius);
    background: #e8f5ef;
    color: var(--accent-strong);
    font-weight: 700;
    margin-bottom: 16px;
    padding: 10px 12px;
}

main {
    display: grid;
    gap: 16px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.metric,
.panel,
.report-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.metric {
    display: grid;
    gap: 6px;
    padding: 14px;
}

.metric span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.metric strong {
    font-size: 21px;
    letter-spacing: 0;
}

.metric small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.grid-two {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    gap: 16px;
}

.panel,
.report-card {
    padding: 16px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.heading-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.panel-heading h1,
.panel-heading h2,
.report-title h2,
.report-card h3 {
    margin: 0;
    letter-spacing: 0;
}

.panel-heading h1,
.panel-heading h2 {
    font-size: 20px;
}

.subsection-heading {
    align-items: baseline;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin: 18px 0 8px;
}

.subsection-heading h2 {
    font-size: 16px;
    margin: 0;
}

.subsection-heading span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.split-heading form {
    margin: 0;
}

.secondary-bank-action {
    border-top: 1px solid var(--line);
    margin-top: 12px;
    padding-top: 12px;
}

.bank-filter-form {
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
    padding-bottom: 12px;
}

.bank-split-layout {
    align-items: start;
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
}

.bank-split-layout .panel {
    min-width: 0;
}

.bank-assignment-select {
    min-width: 230px;
}

.compact-payment-table {
    min-width: 900px;
}

.compact-payment-table th,
.compact-payment-table td {
    padding: 7px 8px;
}

.split-payment-edit-table {
    min-width: 420px;
}

.split-payment-edit-table input {
    max-width: 150px;
}

.stack-form {
    display: grid;
    gap: 12px;
}

.status-note {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfb;
    color: var(--muted);
    font-weight: 800;
    margin: 0;
    padding: 9px 10px;
}

.status-note.is-ok {
    background: #e8f5ef;
    border-color: #bad5ca;
    color: var(--accent-strong);
}

.status-note.is-warning {
    background: #fff7e8;
    border-color: #f0cf91;
    color: #8a5200;
}

.status-note.is-danger {
    background: #fff0f0;
    border-color: #edb8b8;
    color: var(--danger);
}

.panel > .status-note + form {
    margin-top: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.app-dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 20px 48px rgba(23, 33, 27, 0.22);
    color: var(--text);
    max-width: min(560px, calc(100vw - 32px));
    padding: 18px;
    width: 100%;
}

.app-dialog::backdrop {
    background: rgba(23, 33, 27, 0.34);
}

.dialog-heading {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 10px;
}

.dialog-heading h2 {
    font-size: 20px;
    margin: 0;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
}

.icon-close {
    min-height: 32px;
    padding: 4px 10px;
}

.table-wrap {
    overflow-x: auto;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 9px 10px;
    text-align: left;
    vertical-align: middle;
}

th {
    background: #f0f4f2;
    color: #415049;
    font-size: 12px;
    font-weight: 800;
    position: sticky;
    top: 0;
    z-index: 1;
}

td {
    color: #26312b;
}

tfoot th {
    background: #e8f0ec;
}

.edit-table td {
    padding: 6px;
}

.edit-table input,
.edit-table select {
    min-width: 96px;
}

.edit-table input[type="checkbox"] {
    min-width: 0;
    width: 18px;
    height: 18px;
}

.short-input {
    max-width: 110px;
}

.money-input {
    max-width: 150px;
}

.cell-stack {
    display: grid;
    gap: 4px;
    min-width: 150px;
}

.cell-kicker,
.cell-hint {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.25;
}

.cell-hint.is-ok {
    color: var(--ok);
}

.cell-hint.is-warning {
    color: var(--warn);
}

.cell-hint.is-danger {
    color: var(--danger);
}

.signed-input {
    align-items: center;
    display: inline-grid;
    gap: 6px;
    grid-template-columns: auto minmax(120px, 1fr);
}

.signed-input span {
    font-weight: 900;
}

.readonly-value {
    display: inline-flex;
    align-items: center;
    min-height: 35px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f2f5f3;
    color: var(--muted);
    padding: 7px 9px;
    min-width: 96px;
}

.meter-table th.water-cold,
.meter-table td.water-cold {
    background: #e8f4ff;
}

.meter-table th.water-hot,
.meter-table td.water-hot {
    background: #fff0f0;
}

.heat-table {
    min-width: 1120px;
}

.meter-table {
    min-width: 1380px;
}

.cost-table {
    min-width: 1280px;
}

.email-client-table {
    min-width: 1500px;
}

.compact-field-grid {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(2, minmax(130px, 1fr));
}

.hidden-form {
    display: none;
}

.row-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.inline-status {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.tiny-link {
    color: var(--accent-strong);
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    margin-top: 6px;
}

.email-preview {
    margin-top: 8px;
}

.email-preview summary {
    color: var(--accent-strong);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
}

.email-html-preview {
    border: 1px solid var(--line);
    border-radius: 7px;
    height: 520px;
    margin-top: 6px;
    width: min(680px, 80vw);
}

.meter-table th.water-cold {
    color: #1f5f8f;
}

.meter-table th.water-hot {
    color: #8c3737;
}

.meter-table td.water-cold input,
.meter-table td.water-cold .readonly-value {
    background: #f7fbff;
    border-color: #b9d8ef;
}

.meter-table td.water-hot input,
.meter-table td.water-hot .readonly-value {
    background: #fff8f8;
    border-color: #edc4c4;
}

.payment-table th,
.payment-table td {
    min-width: 82px;
}

.payment-table th:first-child,
.payment-table td:first-child {
    min-width: 70px;
}

.payment-table th:nth-child(2),
.payment-table td:nth-child(2) {
    min-width: 160px;
}

.compact-table table {
    min-width: 560px;
}

.formula-table {
    min-width: 1040px;
}

.formula-table td:first-child,
.formula-table td:last-child {
    white-space: nowrap;
}

.formula-table input {
    min-width: 150px;
}

.formula-table td:nth-child(3) input {
    min-width: 240px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.new-row td {
    background: #fbfcfb;
    border-top: 2px solid var(--line-strong);
}

.center {
    text-align: center;
}

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

.compact-table th:nth-child(n+2),
.compact-table td:nth-child(n+2),
.balance-table th:nth-child(n+3),
.balance-table td:nth-child(n+3),
.units-table th:nth-child(1),
.units-table td:nth-child(1),
.units-table th:nth-child(4),
.units-table td:nth-child(4),
.units-table th:nth-child(5),
.units-table td:nth-child(5),
.units-table th:nth-child(6),
.units-table td:nth-child(6),
.meter-table th:nth-child(n+3):nth-child(-n+10),
.meter-table td:nth-child(n+3):nth-child(-n+10),
.heat-table th:nth-child(n+3):nth-child(-n+8),
.heat-table td:nth-child(n+3):nth-child(-n+8),
.cost-table th:nth-child(1),
.cost-table td:nth-child(1),
.cost-table th:nth-child(5),
.cost-table td:nth-child(5),
.cost-table th:nth-child(6),
.cost-table td:nth-child(6),
.cost-table th:nth-child(8),
.cost-table td:nth-child(8),
.payment-table th:nth-child(n+3),
.payment-table td:nth-child(n+3),
.settlement-control-table th:nth-child(n+4):nth-child(-n+7),
.settlement-control-table td:nth-child(n+4):nth-child(-n+7),
.bank-transaction-table th:nth-child(2),
.bank-transaction-table td:nth-child(2),
.split-payment-edit-table th:nth-child(2),
.split-payment-edit-table td:nth-child(2) {
    text-align: right;
}

.units-table th:nth-child(1),
.units-table td:nth-child(1),
.cost-table th:nth-child(10),
.cost-table td:nth-child(10),
.cost-table th:nth-child(11),
.cost-table td:nth-child(11) {
    text-align: center;
}

.units-table td:nth-child(4) input,
.units-table td:nth-child(5) input,
.units-table td:nth-child(6) input,
.meter-table td:nth-child(n+3):nth-child(-n+10) input,
.heat-table td:nth-child(n+3):nth-child(-n+8) input,
.cost-table td:nth-child(1) input,
.cost-table td:nth-child(5) input,
.cost-table td:nth-child(6) input,
.payment-table td:nth-child(n+3) input,
.split-payment-edit-table td:nth-child(2) input {
    text-align: right;
}

.print-table table {
    table-layout: fixed;
}

.print-table th,
.print-table td {
    overflow-wrap: anywhere;
    vertical-align: top;
}

.print-table th.numeric,
.print-table td.numeric {
    text-align: right;
}

.print-table th.numeric {
    white-space: normal;
}

.print-table td.numeric {
    overflow-wrap: normal;
    white-space: nowrap;
}

.summary-table th:first-child,
.summary-table td:first-child {
    width: 65%;
}

.summary-table th:last-child,
.summary-table td:last-child {
    width: 35%;
}

.house-cost-table th:nth-child(1),
.house-cost-table td:nth-child(1) {
    width: 40%;
}

.house-cost-table th:nth-child(2),
.house-cost-table td:nth-child(2) {
    width: 22%;
}

.house-cost-table th:nth-child(3),
.house-cost-table td:nth-child(3) {
    width: 20%;
}

.house-cost-table th:nth-child(4),
.house-cost-table td:nth-child(4) {
    width: 18%;
}

.allocation-table th:nth-child(1),
.allocation-table td:nth-child(1) {
    width: 22%;
}

.allocation-table th:nth-child(2),
.allocation-table td:nth-child(2) {
    width: 20%;
}

.allocation-table th:nth-child(3),
.allocation-table td:nth-child(3),
.allocation-table th:nth-child(4),
.allocation-table td:nth-child(4),
.allocation-table th:nth-child(5),
.allocation-table td:nth-child(5) {
    width: 14%;
}

.allocation-table th:nth-child(6),
.allocation-table td:nth-child(6) {
    width: 16%;
}

.prescription-allocation-table .print-total-label {
    display: none;
}

.settlement-allocation-table th:nth-child(1),
.settlement-allocation-table td:nth-child(1) {
    width: 24%;
}

.settlement-allocation-table th:nth-child(2),
.settlement-allocation-table td:nth-child(2),
.settlement-allocation-table th:nth-child(4),
.settlement-allocation-table td:nth-child(4) {
    width: 18%;
}

.settlement-allocation-table th:nth-child(3),
.settlement-allocation-table td:nth-child(3),
.settlement-allocation-table th:nth-child(5),
.settlement-allocation-table td:nth-child(5) {
    width: 20%;
}

.positive {
    color: var(--ok);
    font-weight: 800;
}

.negative {
    color: var(--danger);
    font-weight: 800;
}

.muted {
    color: var(--muted);
}

.unit-picker {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
}

.unit-picker label {
    min-width: min(420px, 100%);
}

.report-card {
    display: grid;
    gap: 16px;
}

.report-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 2px solid var(--text);
    padding-bottom: 14px;
}

.report-title h2 {
    font-size: 22px;
}

.report-title p {
    margin: 4px 0 0;
    color: var(--muted);
}

.report-unit-box {
    display: grid;
    gap: 4px;
    min-width: 250px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    padding: 12px;
}

.report-unit-box span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.report-unit-box strong {
    font-size: 16px;
}

.report-footer {
    border-top: 1px solid var(--line);
    color: var(--muted);
    display: grid;
    font-size: 12px;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 16px;
    padding-top: 10px;
}

.report-footer span:last-child {
    text-align: right;
}

.report-footer strong {
    color: var(--text);
}

.report-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.house-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.report-summary div,
.month-grid div,
.payment-instructions div {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfb;
    padding: 10px;
}

.report-summary span,
.month-grid span,
.payment-instructions span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.report-summary strong,
.month-grid strong,
.payment-instructions strong {
    display: block;
    font-variant-numeric: tabular-nums;
    margin-top: 4px;
    font-size: 16px;
}

.report-card h3 {
    font-size: 15px;
    margin-top: 2px;
}

.settlement-page {
    display: grid;
    gap: 16px;
}

.settlement-page + .settlement-page {
    border-top: 1px solid var(--line);
    margin-top: 10px;
    padding-top: 18px;
}

.prescription-report-card {
    gap: 0;
}

.prescription-page {
    display: grid;
    gap: 16px;
}

.prescription-page + .prescription-page {
    border-top: 1px solid var(--line);
    margin-top: 10px;
    padding-top: 18px;
}

.prescription-payment-page .report-summary {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.prescription-payment-page .payment-instructions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.prescription-payment-page .payment-instructions .wide-field {
    grid-column: span 2;
}

.settlement-payment-details {
    border-top: 1px solid var(--line);
    margin-top: 18px;
    padding-top: 16px;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}

.payment-instructions {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.qr-payment {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex;
    gap: 16px;
    margin-top: 12px;
    padding: 12px;
}

.qr-code {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    min-height: 172px;
    min-width: 172px;
    padding: 8px;
}

.qr-code svg {
    display: block;
    height: 156px;
    width: 156px;
}

.qr-payment span {
    color: var(--muted);
    display: block;
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 4px;
}

.qr-payment strong {
    font-size: 18px;
}

body.print-preview {
    background: #dfe3e0;
    color: #000;
    font-size: 11px;
    overflow: visible;
}

body.print-preview .app-shell {
    max-width: 100%;
    padding: 12px 0 32px;
    width: auto;
}

body.print-preview .app-header,
body.print-preview .tabs,
body.print-preview .notice,
body.print-preview .print-hidden:not(.unit-picker) {
    display: none !important;
}

body.print-preview .unit-picker {
    display: flex !important;
    margin: 0 auto 12px;
    max-width: 210mm;
    position: sticky;
    top: 8px;
    z-index: 20;
}

body.print-preview main {
    display: block;
    margin: 0 auto;
    max-width: 210mm;
    width: 100%;
}

body.print-preview .report-card {
    background: #fff;
    border: 0;
    border-radius: 0;
    box-shadow: 0 14px 34px rgba(23, 33, 27, 0.2);
    display: block;
    margin: 0 auto 18px;
    max-width: 100%;
    min-height: 297mm;
    padding: 15mm;
    width: 210mm;
}

body.print-preview .settlement-report-card {
    background: transparent;
    box-shadow: none;
    min-height: 0;
    padding: 0;
    width: 100%;
}

body.print-preview .prescription-report-card {
    background: transparent;
    border: 0;
    box-shadow: none;
    min-height: 0;
    padding: 0;
    width: 100%;
}

body.print-preview .settlement-page {
    background: #fff;
    box-shadow: 0 14px 34px rgba(23, 33, 27, 0.2);
    display: grid;
    gap: 12px;
    margin: 0 auto 18px;
    min-height: 297mm;
    padding: 15mm;
    width: 210mm;
}

body.print-preview .prescription-page {
    background: #fff;
    box-shadow: 0 14px 34px rgba(23, 33, 27, 0.2);
    display: grid;
    gap: 12px;
    margin: 0 auto 18px;
    min-height: 297mm;
    padding: 15mm;
    width: 210mm;
}

body.print-preview .settlement-page + .settlement-page {
    border-top: 0;
    margin-top: 0;
    padding-top: 15mm;
}

body.print-preview .prescription-page + .prescription-page {
    border-top: 0;
    margin-top: 0;
    padding-top: 15mm;
}

body.print-preview .settlement-payment-details {
    border-top: 0;
    margin-top: 0;
    padding-top: 0;
}

body.print-preview .report-summary,
body.print-preview .month-grid,
body.print-preview .payment-instructions {
    gap: 4mm;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.print-preview .house-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.print-preview .prescription-payment-page .report-summary {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.print-preview .prescription-payment-page .payment-instructions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

body.print-preview .prescription-payment-page .payment-instructions .wide-field {
    grid-column: span 2;
}

body.print-preview .report-title {
    display: grid;
    gap: 6mm;
    grid-template-columns: minmax(0, 1fr) minmax(0, 62mm);
}

body.print-preview .report-title > div,
body.print-preview .report-summary div,
body.print-preview .month-grid div,
body.print-preview .payment-instructions div,
body.print-preview .qr-payment,
body.print-preview .qr-payment > div {
    max-width: 100%;
    min-width: 0;
}

body.print-preview .report-title h2 {
    font-size: 18px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

body.print-preview .report-title p,
body.print-preview .report-unit-box span,
body.print-preview .report-unit-box strong,
body.print-preview .report-summary strong,
body.print-preview .payment-instructions strong,
body.print-preview .qr-payment strong {
    overflow-wrap: anywhere;
    word-break: normal;
}

body.print-preview .report-summary strong,
body.print-preview .payment-instructions strong {
    font-size: 13px;
}

body.print-preview .report-unit-box {
    min-width: 0;
    padding: 8px;
    width: 100%;
}

body.print-preview .qr-payment {
    max-width: 100%;
}

body.print-preview .qr-code {
    flex: 0 0 38mm;
    min-height: 38mm;
    min-width: 0;
    width: 38mm;
}

body.print-preview .qr-code svg {
    height: 34mm;
    width: 34mm;
}

body.print-preview .table-wrap {
    max-width: 100%;
    overflow: visible;
    width: 100%;
}

body.print-preview table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 9.8px;
    max-width: 100%;
    min-width: 0;
    width: 100%;
}

body.print-preview th {
    position: static;
}

body.print-preview th,
body.print-preview td {
    max-width: 1px;
    overflow-wrap: anywhere;
    padding: 3.5px 4.5px;
}

body.print-preview .report-footer {
    break-inside: avoid;
    font-size: 10px;
    margin-top: auto;
    padding-top: 3mm;
}

body.print-preview .prescription-allocation-table .print-optional,
body.print-preview .prescription-allocation-table .screen-total-label {
    display: none;
}

body.print-preview .prescription-allocation-table .print-total-label {
    display: table-cell;
}

body.print-preview .prescription-allocation-table th:nth-child(1),
body.print-preview .prescription-allocation-table td:nth-child(1) {
    width: 50%;
}

body.print-preview .prescription-allocation-table th:nth-child(5),
body.print-preview .prescription-allocation-table td:nth-child(5),
body.print-preview .prescription-allocation-table th:nth-child(6),
body.print-preview .prescription-allocation-table td:nth-child(6) {
    width: 25%;
}

.auth-body {
    min-height: 100vh;
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    padding: 18px;
    place-items: center;
}

.auth-panel {
    display: grid;
    gap: 16px;
    max-width: 440px;
    width: min(440px, 100%);
}

.auth-brand {
    min-width: 0;
}

.auth-link {
    margin: 0;
}

.auth-link a {
    color: var(--accent-strong);
    font-weight: 800;
}

.users-table {
    min-width: 1120px;
}

.users-table td:nth-child(1),
.users-table th:nth-child(1) {
    width: 76px;
}

.users-table td:nth-child(7),
.users-table th:nth-child(7) {
    width: 150px;
}

.password-panel {
    max-width: 680px;
}

.public-settlement-body .app-shell {
    max-width: none;
    width: 100%;
}

.public-settlement-body .settlement-report-card {
    box-shadow: none;
}

.public-settlement-toolbar,
.public-refund-panel {
    box-shadow: var(--shadow);
}

.refund-request-body {
    background: rgba(23, 33, 27, 0.12);
    min-height: 100vh;
}

.refund-popup-shell {
    display: grid;
    min-height: 100vh;
    padding: 18px;
    place-items: center;
}

.refund-popup {
    width: min(720px, 100%);
}

.refund-request-panel {
    box-shadow: 0 18px 44px rgba(23, 33, 27, 0.18);
}

.refund-request-copy {
    color: var(--muted);
    margin: 0;
}

.refund-thank-you {
    background: var(--accent-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: grid;
    gap: 6px;
    padding: 16px;
}

.refund-thank-you strong {
    color: var(--accent-strong);
    font-size: 20px;
}

.refund-thank-you span {
    color: var(--muted);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

@media (max-width: 980px) {
    .app-header,
    .report-title {
        align-items: stretch;
        flex-direction: column;
    }

    .context-switcher,
    .unit-picker {
        align-items: stretch;
        justify-content: stretch;
        flex-wrap: wrap;
    }

    .context-switcher label,
    .unit-picker label {
        min-width: 220px;
        flex: 1 1 220px;
    }

    .metric-grid,
    .grid-two,
    .bank-split-layout,
    .report-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .month-grid,
    .payment-instructions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .house-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .qr-payment {
        align-items: flex-start;
    }
}

@media (max-width: 620px) {
    .app-shell {
        padding: 10px 9px 32px;
    }

    .metric-grid,
    .grid-two,
    .bank-split-layout,
    .form-row,
    .report-summary,
    .month-grid,
    .payment-instructions {
        grid-template-columns: 1fr;
    }

    .qr-payment {
        align-items: stretch;
        flex-direction: column;
    }

    .prescription-payment-page .payment-instructions .wide-field {
        grid-column: auto;
    }

    .qr-code {
        min-width: 0;
        width: 100%;
    }

    .house-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .panel,
    .report-card {
        padding: 12px;
    }

    .brand {
        min-width: 0;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 15mm;
    }

    html,
    body {
        background: #fff;
        color: #000;
        font-size: 11px;
        overflow: visible;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .app-shell {
        max-width: 100%;
        padding: 0;
        width: auto;
    }

    .app-header,
    .tabs,
    .notice,
    .public-settlement-toolbar,
    .public-refund-panel,
    .print-hidden {
        display: none !important;
    }

    main {
        display: block;
        max-width: 100%;
        width: 100%;
    }

    .report-card {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        display: block;
        padding: 0;
        break-after: page;
        max-width: 100%;
        width: 100%;
    }

    .report-card:last-child {
        break-after: auto;
    }

    .report-card:not(.settlement-report-card):not(.prescription-report-card),
    .settlement-page {
        min-height: calc(297mm - 30mm);
    }

    .report-card:not(.settlement-report-card):not(.prescription-report-card) {
        display: grid;
        gap: 12px;
    }

    .prescription-report-card {
        break-after: auto;
        display: block;
        min-height: 0;
    }

    .prescription-page {
        break-after: page;
        break-inside: auto;
        display: grid;
        gap: 12px;
        min-height: calc(297mm - 30mm);
        page-break-after: always;
        page-break-inside: auto;
    }

    .prescription-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    .prescription-page + .prescription-page {
        border-top: 0;
        margin-top: 0;
        padding-top: 0;
    }

    .report-footer {
        break-inside: avoid;
        font-size: 10px;
        margin-top: auto;
        padding-top: 3mm;
    }

    .report-summary,
    .month-grid,
    .payment-instructions {
        gap: 4mm;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .house-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .prescription-payment-page .report-summary {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .prescription-payment-page .payment-instructions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .prescription-payment-page .payment-instructions .wide-field {
        grid-column: span 2;
    }

    .report-title {
        display: grid;
        gap: 6mm;
        grid-template-columns: minmax(0, 1fr) minmax(0, 62mm);
    }

    .report-title > div,
    .report-summary div,
    .month-grid div,
    .payment-instructions div,
    .qr-payment,
    .qr-payment > div {
        min-width: 0;
        max-width: 100%;
    }

    .report-title h2 {
        font-size: 18px;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    .report-title p,
    .report-unit-box span,
    .report-unit-box strong,
    .report-summary strong,
    .payment-instructions strong,
    .qr-payment strong {
        overflow-wrap: anywhere;
        word-break: normal;
    }

    .report-summary strong,
    .payment-instructions strong {
        font-size: 13px;
    }

    .report-unit-box {
        min-width: 0;
        padding: 8px;
        width: 100%;
    }

    .qr-payment {
        break-inside: avoid;
        max-width: 100%;
    }

    .qr-code {
        flex: 0 0 38mm;
        min-height: 38mm;
        min-width: 0;
        width: 38mm;
    }

    .qr-code svg {
        height: 34mm;
        width: 34mm;
    }

    .prescription-allocation-table .print-optional,
    .prescription-allocation-table .screen-total-label {
        display: none;
    }

    .prescription-allocation-table .print-total-label {
        display: table-cell;
    }

    .prescription-allocation-table th:nth-child(1),
    .prescription-allocation-table td:nth-child(1) {
        width: 50%;
    }

    .prescription-allocation-table th:nth-child(5),
    .prescription-allocation-table td:nth-child(5),
    .prescription-allocation-table th:nth-child(6),
    .prescription-allocation-table td:nth-child(6) {
        width: 25%;
    }

    .settlement-page {
        break-inside: auto;
        display: grid;
        gap: 12px;
        page-break-inside: auto;
    }

    .settlement-page + .settlement-page {
        border-top: 0;
        break-before: page;
        margin-top: 0;
        page-break-before: always;
        padding-top: 15mm;
    }

    .settlement-payment-details {
        border-top: 0;
        margin-top: 0;
        padding-top: 0;
    }

    .table-wrap {
        max-width: 100%;
        overflow: visible;
        width: 100%;
    }

    table {
        border-collapse: separate;
        border-spacing: 0;
        min-width: 0;
        font-size: 10px;
        max-width: 100%;
        width: 100%;
    }

    th {
        position: static;
        background: #eee;
    }

    th,
    td {
        border: 0;
        box-shadow: inset 0 0 0 0.5pt #aebbb3;
        max-width: 1px;
        overflow-wrap: anywhere;
        padding: 4px 5px;
    }

    .report-summary div,
    .month-grid div,
    .payment-instructions div,
    .report-unit-box,
    .qr-payment,
    .qr-code {
        border: 0;
        box-shadow: inset 0 0 0 0.5pt #aebbb3;
    }
}
