/* The item picker lives in the modal's top layer, outside the table scroller. */
[data-entry-grid] :is(input,select):focus { outline:2px solid #24956b; outline-offset:1px; }
[data-entry-grid] :is(tr,.recipe-line,.package-row):focus-within { background:#f0f7f3; }
[data-entry-grid] [data-entry-mode="navigation"]:focus { background:#e8f3ed; }
@media(min-width:651px) {
  #recipe-dialog form { display:flex; flex-direction:column; height:100%; min-height:0; overflow:hidden; }
  #recipe-ingredients-editor { flex:1 1 auto; min-height:140px; overflow:auto; }
  #recipe-dialog form > :not(#recipe-ingredients-editor) { flex:0 0 auto; }
  #transfer-dialog { height:calc(100dvh - 24px); overflow:hidden; }
  #transfer-form { display:flex; flex-direction:column; height:100%; min-height:0; overflow:hidden; }
  #transfer-form > :not(#transfer-lines-editor) { flex:0 0 auto; }
  #transfer-lines-editor { flex:1 1 auto; min-height:140px; max-height:none; overflow:auto; }
}
dialog .document-item-results {
  position:fixed;
  inset:auto;
  margin:0;
  box-sizing:border-box;
  padding:5px;
  min-width:0;
  max-width:none;
  overflow:auto;
  overscroll-behavior:contain;
  z-index:160;
  border:1px solid #cdded3;
  border-radius:10px;
  background:white;
  box-shadow:0 10px 30px #183e2b30;
}
dialog .document-item-results button { min-height:38px; }
dialog .document-item-results button[aria-selected="true"] { background:#e8f3ed; color:#145b40; outline:1px solid #a6cdb8; outline-offset:-1px; }
#document-dialog .document-entry-help { margin-top:4px; color:#718078; font-size:10px; }
#document-dialog .document-entry-help[hidden] { display:none; }
#document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) #document-lines-editor tr:focus-within td { background:#f0f7f3; }
#document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) #document-lines-editor input:not(:focus) { box-shadow:none; border-color:#e1e8e3; }
#document-dialog[data-document-type="receipt"] #document-lines-editor .unit-price-cell input:not(:focus) { background:white; color:var(--ink); }
#document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) #document-lines-editor :is(input,select):focus { border-color:#24956b; outline:2px solid #24956b; outline-offset:1px; box-shadow:none; }
#document-dialog #document-lines-editor [data-entry-mode="navigation"]:focus { background:#e8f3ed; caret-color:transparent; }
#document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) #document-lines-editor :is(input,select) { scroll-margin-block:42px 12px; }
@media(max-width:650px) {
  [data-entry-grid] { flex-shrink:0; }
  #item-dialog .recipe-table,#recipe-dialog .recipe-table { max-width:100%; overflow-x:auto; }
  /* Cards must contribute their full height to the scrolling form. Otherwise
     flex shrinks the editor to its padding and the footer sits above the rows. */
  #document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) .document-lines-editor { flex:0 0 auto; }
  dialog .document-item-results button { min-height:46px; }
  dialog .document-item-results button b { font-size:14px; }
  #document-dialog .document-entry-help { display:none; }
  #document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) #document-lines-editor :is(input,select) { scroll-margin-block:20px 100px; }
}
@media(min-width:651px) and (max-height:600px) {
  #item-dialog form,#recipe-dialog form,#transfer-form { overflow-y:auto; }
  #item-dialog .item-tab-panel.active { flex:0 0 auto; overflow:visible; }
  #recipe-ingredients-editor,#transfer-lines-editor { flex:0 0 auto; min-height:140px; max-height:45vh; overflow:auto; }
  #item-dialog .dialog-footer,#recipe-dialog .dialog-footer,#transfer-dialog .dialog-footer { position:sticky; bottom:0; z-index:40; }
  #document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) form { overflow-y:auto; }
  #document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) .document-lines-editor { flex:0 0 auto; min-height:140px; max-height:45vh; }
  #document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) .document-footer { position:sticky; bottom:0; z-index:40; }
  #document-dialog:is([data-document-type="receipt"],[data-document-type="writeoff"],[data-document-type="inventory"],[data-document-type="sale"],[data-document-type="production"]) #document-lines-editor :is(input,select) { scroll-margin-block:42px 90px; }
}
