/* Five complete data-row spaces, measured with the account's font/control size.
   The historical class/variable name is retained for existing screen styles. */
body .entry-screen .entry-four-row-grid {
 --entry-grid-four-rows:max(calc((var(--form-height,28px) + 6px) * 5 + 48px),var(--entry-grid-measured,0px));
 height:var(--entry-grid-four-rows)!important;
 min-height:var(--entry-grid-four-rows)!important;
 max-height:none!important;
 flex:1 0 var(--entry-grid-four-rows)!important;
 overflow:auto!important;
 overflow-anchor:none;
 box-sizing:border-box;
}
/* Internal scrolling absorbs long headers/details; the 654px frame and actions stay fixed. */
body .entry-screen > .locksmith-entry-content:has(.entry-four-row-grid) {overflow-y:auto!important;}
body .product-content > .vfp-product-tabpanel:has(.entry-four-row-grid) {
 flex:0 0 auto!important;min-height:min-content;overflow:visible!important;
}
body .bom-grid-wrap:has(> .entry-four-row-grid) {
 min-height:var(--entry-grid-wrap-min,280px)!important;
 flex:1 0 auto!important;
}
@media(max-width:850px) {
 body .entry-screen .entry-four-row-grid {flex-grow:0!important;}
}
body .bom-grid.entry-four-row-grid .bom-grid-row {
 height:max(30px,calc(var(--form-height,28px) + 2px));
 min-height:max(30px,calc(var(--form-height,28px) + 2px));
}
/* GRN: scroll the long document fields and totals separately; keep item rows in view. */
.stores-document-fields,.stores-line-items,.stores-summary-fields{display:contents}
@media(min-width:851px){
 body .receipt-grid-layout>.locksmith-entry-content,
 body .receipt-grid-layout>.locksmith-entry-content:has(.entry-four-row-grid){display:flex;flex-direction:column;gap:6px;padding:8px 12px;overflow:hidden!important}
 body .receipt-grid-layout .stores-document-fields{display:block;flex:0 1 112px;min-height:56px;overflow:auto;overscroll-behavior:contain}
 body .receipt-grid-layout .stores-line-items{display:flex;flex-direction:column;flex:1 0 auto;min-height:0;gap:4px}
 body .receipt-grid-layout .stores-summary-fields{display:block;flex:0 1 80px;min-height:32px;overflow:auto;overscroll-behavior:contain}
 body .receipt-grid-layout .quality-toolbar{flex:0 0 auto;margin:2px 0}
 body .receipt-grid-layout .quality-header{gap:5px 12px}
 body .receipt-grid-layout .quality-header>label{display:grid;grid-template-columns:120px minmax(0,1fr);gap:5px;align-items:center;line-height:1.3}
 body .receipt-grid-layout .stores-line-items>.quality-line-details{flex:0 1 80px;max-height:80px;min-height:0;overflow:auto;padding:4px 0}
 body .receipt-grid-layout .stores-line-items>.quality-grid{margin:0;max-height:none}
}
/* Purchase Bill follows Close PO: compact header, central items, short totals strip. */
.bill-document-fields,.bill-line-items,.bill-summary-fields{display:contents}
body .account-bill-vfp .quality-header>label{display:grid;grid-template-columns:100px minmax(0,1fr);align-items:center;gap:4px;line-height:1.2}
body .account-bill-vfp .quality-header{gap:4px 12px}
body .account-bill-vfp .quality-control{gap:4px}
body .account-bill-vfp>.master-actions{display:flex;flex-wrap:wrap;gap:6px;margin:0;padding:8px}
body .account-bill-vfp>.master-actions>button[data-ui-button][data-ui-button][data-ui-button]{min-width:58px;min-height:30px;padding:6px 9px;gap:5px;flex:1 0 auto}
body .account-bill-vfp .quality-content button[data-ui-button][data-ui-button][data-ui-button]{min-height:var(--form-height,28px);padding:4px 8px;gap:4px}
body .account-bill-vfp .quality-control button[data-ui-button][data-ui-button][data-ui-button]{min-width:var(--form-height,28px);width:var(--form-height,28px);flex:0 0 var(--form-height,28px);padding:4px;font-size:0;gap:0}
body .account-bill-vfp .quality-grid table{margin:0;width:max-content;min-width:100%}
body .account-bill-vfp .quality-grid :is(th,td){padding:3px 6px}
body .account-bill-vfp .quality-grid :is(th,td):last-child{position:sticky;right:0;background:var(--locksmith-panel,#f5f6ed);box-shadow:-1px 0 var(--locksmith-border,#cad4c7)}
body .account-bill-vfp .quality-grid th:last-child{z-index:2}
body .account-bill-vfp .quality-grid tr.selected td:last-child{background:var(--skin-soft,#dce8d6)}
body .account-bill-vfp .bill-totals-strip{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:4px 12px;padding:5px 8px;border-block:1px solid var(--locksmith-border,#cad4c7);background:var(--skin-soft,#eef1e7)}
body .account-bill-vfp .bill-totals-strip>div{min-width:0;text-align:right}
body .account-bill-vfp .bill-totals-strip span{display:block;font-size:.9em;line-height:1.2}
body .account-bill-vfp .bill-totals-strip output{display:block;font-weight:600;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
body .account-bill-vfp .bill-totals-strip .bill-net-total output{font-weight:800;color:var(--locksmith-text,#183c2b)}
body .account-bill-vfp .locksmith-status:empty{display:none}
@media(min-width:851px){
 body .account-bill-grid-layout>.locksmith-entry-content,
 body .account-bill-grid-layout>.locksmith-entry-content:has(.entry-four-row-grid){display:flex;flex-direction:column;gap:5px;padding:6px 12px;overflow:hidden!important}
 body .account-bill-grid-layout .bill-document-fields{display:block;flex:0 1 132px;min-height:64px;overflow:auto;overscroll-behavior:contain}
 body .account-bill-grid-layout .bill-line-items{display:flex;flex-direction:column;flex:1 0 auto;min-height:0;gap:3px}
 body .account-bill-grid-layout .bill-summary-fields{display:block;flex:0 1 82px;min-height:42px;overflow:auto;overscroll-behavior:contain}
 body .account-bill-grid-layout .quality-toolbar{flex:0 0 auto;gap:6px;margin:0}
 body .account-bill-grid-layout .bill-line-items>.quality-line-details{flex:0 1 64px;min-height:0;max-height:64px;overflow:auto;padding:3px 0}
 body .account-bill-grid-layout .bill-line-items>.quality-grid{margin:0;max-height:none}
}
@container(min-width:1000px){body .account-bill-vfp .bill-document-fields>.quality-header{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media(max-width:850px){
 body .account-bill-vfp .bill-totals-strip{grid-template-columns:repeat(3,minmax(0,1fr));margin-top:6px}
 body .account-bill-vfp .bill-line-items>.quality-grid{margin-block:6px}
}
@media(max-width:480px){body .account-bill-vfp .quality-header>label{grid-template-columns:1fr}body .account-bill-vfp .bill-totals-strip{grid-template-columns:repeat(2,minmax(0,1fr))}}

/* Compact shared bill footer keeps return-note print modes beside the actions. */
body .account-bill-vfp>.master-actions>label{display:flex;align-items:center;gap:4px;font-size:12px}
body .account-bill-vfp>.master-actions>label select{width:100px;min-width:0}
body .account-bill-vfp .quality-toolbar>label{display:flex;align-items:center;gap:4px}
body .account-bill-vfp .quality-toolbar>label select{width:105px;min-width:0}
/* Expenses uses the same fixed-frame composition with its existing journal fields. */
.expenses-document-fields,.voucher-line-narration{display:contents}
body .expenses-vfp{position:relative;container-type:inline-size}
body .expenses-vfp .cash-summary{margin:0 0 5px;font-size:.9em}
body .expenses-vfp .cash-header{gap:4px 12px}
body .expenses-vfp .cash-header>label{display:grid;grid-template-columns:105px minmax(0,1fr);align-items:center;gap:4px;font-weight:500;line-height:1.2}
body .expenses-vfp .cash-narration textarea{height:var(--form-height,28px);min-height:var(--form-height,28px);resize:vertical}
body .expenses-vfp .voucher-line-narration{display:flex;align-items:center;gap:4px}
body .expenses-vfp .journal-lines textarea{height:var(--form-height,28px);min-height:var(--form-height,28px);resize:vertical}
body .expenses-vfp .journal-lines :is(th,td){padding:3px 6px}
body .expenses-vfp .journal-lines small{margin-top:2px}
body .expenses-vfp .journal-lines .bank-cheque{margin-top:3px;padding-top:3px}
body .expenses-vfp .closepo-content button[data-ui-button][data-ui-button][data-ui-button]{min-height:var(--form-height,28px);padding:4px 7px;gap:4px}
body .expenses-vfp :is(.closepo-picker,.voucher-line-narration)>button[data-ui-button][data-ui-button][data-ui-button]{flex:0 0 var(--form-height,28px);width:var(--form-height,28px);min-width:var(--form-height,28px);padding:4px;font-size:0;gap:0}
body .expenses-vfp .cash-totals{padding:4px 0;gap:12px}
body .expenses-vfp>.master-actions>button[data-ui-button][data-ui-button][data-ui-button]{min-width:58px;min-height:30px;padding:6px 9px;gap:5px}
body .expenses-vfp .cash-posting{margin:0;padding:4px 8px}
@media(min-width:851px){
 body .expenses-vfp>.locksmith-entry-content,
 body .expenses-vfp>.locksmith-entry-content:has(.entry-four-row-grid){display:flex;flex-direction:column;gap:5px;padding:6px 12px;overflow:hidden!important}
 body .expenses-vfp .expenses-document-fields{display:block;flex:0 1 100px;min-height:48px;overflow:auto;overscroll-behavior:contain}
 body .expenses-vfp .journal-lines{margin:0;flex:1 0 auto}
 body .expenses-vfp :is(.cash-totals,.cash-posting){flex:0 0 auto}
 body .expenses-vfp .cash-posting[open]{position:absolute;left:12px;right:12px;bottom:62px;z-index:5;max-height:300px;overflow:auto;box-shadow:0 4px 16px #203c2333}
 body .expenses-vfp .cash-posting[open]>[data-grid-scroll]{height:245px!important;min-height:245px!important;flex:none!important}
}
@media(max-width:850px){body .expenses-vfp .cash-header{grid-template-columns:1fr 1fr}}
@media(max-width:550px){body .expenses-vfp .cash-header{grid-template-columns:1fr}body .expenses-vfp .cash-header>label{grid-template-columns:1fr}}

/* All entry families share the same opening composition: title and actions stay
   outside the body; document/detail areas yield space before the item grids do.
   JS marks existing ancestor paths without moving any Blazor-owned elements. */
body .entry-grid-visible .quality-toolbar[role="group"] button[aria-pressed="true"]{outline:2px solid var(--entry-green,#3d5f48);outline-offset:-2px}
@media(min-width:851px){
 body .entry-screen.entry-grid-visible>.vfp-title{min-height:40px;padding:6px 12px}
 body .entry-screen.entry-grid-visible>.master-actions{padding:5px 8px;gap:5px;margin:0;flex:0 0 auto}
 body .entry-screen.entry-grid-visible>.master-actions>button[data-ui-button][data-ui-button][data-ui-button]{min-height:var(--form-height,28px);min-width:58px;padding:4px 8px;gap:5px}
 body .entry-screen.entry-grid-visible .entry-layout-stack{display:flex!important;flex-direction:column!important;gap:4px!important;min-width:0;min-height:var(--entry-layout-min,0px)!important;flex:1 1 0!important;overflow:hidden!important;max-height:none!important}
 body .entry-screen.entry-grid-visible>.locksmith-entry-content.entry-layout-stack{min-height:0!important;padding:6px 10px!important;scrollbar-gutter:auto}
 body .entry-screen.entry-grid-visible .entry-layout-stack>.entry-layout-support{flex:0 1 auto!important;min-height:28px;max-height:220px;overflow:auto!important;overscroll-behavior:contain;margin-block:0;box-sizing:border-box}
 body .entry-screen.entry-grid-visible .entry-layout-stack>.entry-layout-block{display:block!important}
 body .entry-screen.entry-grid-visible .entry-layout-stack>:is(.quality-toolbar,.purchase-request-toolbar,.quality-paging,.master-paging,.production-grid-footer,.bom-grid-footer,.bom-line-actions,.vfp-child-actions,.account-opening-controls,.account-opening-summary){min-height:24px;max-height:40px;padding-block:2px;gap:6px}
 body .entry-screen.entry-grid-visible .entry-layout-stack>:is(.quality-toolbar,.purchase-request-toolbar,.quality-paging,.master-paging,.bom-line-actions,.account-opening-controls,.cash-totals,.opening-stock-tools,.opening-stock-location):has(button,input,select){min-height:calc(var(--form-height,28px) + 4px);max-height:calc(var(--form-height,28px) + 8px)}
 body .entry-screen.entry-grid-visible .entry-layout-stack>:is(.locksmith-status,p,h3){min-height:20px;max-height:40px;padding-block:0}
 body .entry-screen.entry-grid-visible .entry-layout-stack>:is(.locksmith-status,p):empty{display:none}
 body .entry-screen.entry-grid-visible .entry-layout-stack>details{min-height:24px;max-height:80px}
 body .entry-screen.entry-grid-visible .entry-layout-stack>.quality-line-details{min-height:24px;max-height:72px;padding:2px 0}
 body .entry-screen.entry-grid-visible .entry-four-row-grid{--entry-grid-four-rows:max(calc((var(--form-height,28px) + 6px) * 5 + 48px),var(--entry-grid-measured,0px));margin-block:0;flex:1 0 var(--entry-grid-four-rows)!important}
 body .entry-screen.entry-grid-visible .entry-four-row-grid table{margin:0;width:max-content;min-width:100%}
 body .entry-screen.entry-grid-visible .entry-four-row-grid :is(th,td){padding:2px 5px;white-space:nowrap;line-height:1.3}
 body .entry-screen.entry-grid-visible .entry-four-row-grid th{position:sticky;top:0;z-index:1}
 body .entry-screen.entry-grid-visible .entry-four-row-grid :is(input,select,textarea){min-height:var(--form-height,28px);box-sizing:border-box}
 body .entry-screen.entry-grid-visible .entry-four-row-grid textarea{height:var(--form-height,28px);resize:vertical}
 body .entry-screen.entry-grid-visible .entry-four-row-grid button[data-ui-button][data-ui-button][data-ui-button]{min-height:var(--form-height,28px);padding:3px 6px;gap:4px}
 body .entry-screen.entry-grid-visible .entry-layout-support button[data-ui-button][data-ui-button][data-ui-button]{min-height:var(--form-height,28px);padding:3px 6px;gap:4px}
 body .entry-screen.entry-grid-visible .quality-header{gap:4px 12px}
 body .entry-screen.entry-grid-visible .quality-header>label{display:grid;grid-template-columns:minmax(85px,115px) minmax(0,1fr);gap:4px;align-items:center;line-height:1.2}
 body .entry-screen.entry-grid-visible :is(.structured-fields,.master-fields,.bulk-search,.cash-header){padding-block:4px;gap:4px 12px}
 body .entry-screen.entry-grid-visible .cash-header>label{display:grid;grid-template-columns:100px minmax(0,1fr);align-items:center;gap:4px;line-height:1.2}
 body .entry-screen.entry-grid-visible .cash-header>label>small{grid-column:2;margin:0}
 body .entry-screen.entry-grid-visible .cash-header textarea{height:var(--form-height,28px);min-height:var(--form-height,28px);resize:vertical}
 body .entry-screen.entry-grid-visible .purchase-request-top{display:block}
 body .entry-screen.entry-grid-visible .bom-grid-wrap.entry-layout-stack{min-height:var(--entry-layout-min,0px)!important}
 body .entry-screen.entry-grid-visible .vfp-product-tabpanel.entry-layout-stack{flex:1 1 0!important;min-height:var(--entry-layout-min,0px)!important;overflow:hidden!important}
 body .entry-screen.entry-grid-visible :is(.user-menu-columns,[data-entry-grid-pair]).entry-layout-stack{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px!important}
 body .entry-screen.entry-grid-visible .entry-layout-stack>.entry-four-row-grid.product-child-grid{padding:4px}
 body .entry-screen.entry-grid-visible .invoice-bottom-band{max-height:80px}
 body .entry-screen.entry-grid-visible{position:relative}
 body .entry-screen.entry-grid-visible .cash-posting:not([open]){padding:2px 6px;min-height:max(28px,calc(var(--form-size,13px) * 1.3 + 6px));max-height:40px}
 body .entry-screen.entry-grid-visible .cash-posting:not([open])>summary{line-height:1.3}
 body .entry-screen.entry-grid-visible .cash-posting[open]{position:absolute;left:10px;right:10px;bottom:52px;z-index:5;max-height:calc(100% - 100px);overflow:auto;background:var(--locksmith-panel,#f5f6ed);border:1px solid var(--entry-border);padding:6px;box-shadow:0 4px 16px #203c2333}
 body .entry-screen.entry-grid-visible .cash-posting[open]>[data-grid-scroll]{height:var(--entry-grid-four-rows)!important;min-height:var(--entry-grid-four-rows)!important}
 body .monthly-order-workbench.entry-grid-visible .entry-layout-stack>.purchase-request-top{min-height:24px}
 body .monthly-order-workbench.entry-grid-visible .entry-layout-stack>.production-grid-footer{min-height:20px;padding-block:0;line-height:1.2}
 body .monthly-order-workbench.entry-grid-visible .entry-layout-stack>.purchase-line-details:not([open]){min-height:20px}
 body .monthly-order-workbench.entry-grid-visible .purchase-line-details>summary{line-height:1.2}
 body .monthly-order-workbench.entry-grid-visible:not(:has(.monthly-order-document[open]))>.locksmith-entry-content.entry-layout-stack{padding-block:4px!important;gap:2px!important}
 body .monthly-order-workbench.entry-grid-visible:not(:has(.monthly-order-document[open])) .entry-layout-stack>.purchase-request-top{min-height:20px}
 body .monthly-order-workbench.entry-grid-visible .monthly-order-document:not([open])>summary{line-height:1.2}
 body .entry-screen.entry-grid-visible [hidden]{display:none!important}
}

/* Keep voucher lines and postings in independent grids so the form actions stay in view. */
@media (min-width: 851px) and (min-height: 600px) {
 body .entry-screen.compact-entry.account-voucher-layout {
  height: 654px;
  max-height: calc(100dvh - 124px);
 }
 body .entry-screen.account-voucher-layout > .vfp-title {
  min-height: 38px;
  padding: 4px 12px;
 }
 body .account-voucher-layout > .closepo-content {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px 10px;
 }
 body .account-voucher-layout .cash-summary {
  margin: 0;
  line-height: 1.35;
 }
 body .entry-screen.account-voucher-layout .cash-header {
  flex: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px 9px;
  padding: 5px 8px;
 }
 body .account-voucher-layout .cash-header > label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 5px;
  margin: 0;
  line-height: 1.25;
 }
 body .account-voucher-layout .cash-header > label > small { grid-column: 2; }
 body .account-voucher-layout .cash-narration { grid-column: 1 / -1; }
 body .account-voucher-layout :is(.cash-narration, .closepo-grid) textarea {
  min-height: var(--form-height, 28px);
  height: var(--form-height, 28px);
 }
 body .entry-screen.account-voucher-layout .closepo-content > .closepo-grid {
  flex: 1 1 0 !important;
  height: auto !important;
  min-height: 92px !important;
  margin: 0;
 }
 body .account-voucher-layout .closepo-grid :is(th, td) { padding: 3px 5px; }
 body .account-voucher-layout .cash-totals {
  flex: none;
  gap: 6px 12px;
  padding: 2px 0;
 }
 body .account-voucher-layout .cash-posting {
  flex: none;
  margin: 0;
  padding: 3px 6px;
 }
 body .entry-screen.account-voucher-layout .cash-posting > [data-grid-scroll] {
  height: auto !important;
  min-height: 0 !important;
  max-height: clamp(70px, 16dvh, 126px) !important;
 }
 body .account-voucher-layout .cash-posting :is(th, td) { padding: 2px 5px; }
 body .entry-screen.account-voucher-layout > .cash-actions {
  min-height: 0;
  gap: 5px;
  padding: 5px 8px 7px;
 }
 body .entry-screen.account-voucher-layout > .cash-actions > [data-ui-button][data-ui-button][data-ui-button] {
  min-width: 0;
  min-height: 30px;
  padding: 4px 8px;
 }
}
