/* Compact field layout for shared operational forms.
 * Layout rules target real field groups, never every input or every grid.
 * Tables, long notes, autocomplete menus, calendars and printed documents keep
 * their own layout/scroll ownership. No structural transforms or clipping.
 */
@media screen {
  body.hms-executive-ui.hms-ui-density-compact {
    --hms-field-gap: 8px;
    --hms-field-width: 240px;
  }
  /* Reusable contract for new field rows. A long description can opt into wide. */
  body.hms-executive-ui .hms-field-row {
    display:flex; align-items:flex-end; flex-wrap:wrap; gap:var(--hms-field-gap,8px);
  }
  body.hms-executive-ui .hms-field-row > .hms-field {
    display:grid; gap:4px; flex:0 1 var(--hms-field-width,240px); min-width:0; max-width:100%;
  }
  body.hms-executive-ui .hms-field-row > .hms-field-short { flex-basis:150px; }
  body.hms-executive-ui .hms-field-row > .hms-field-wide { flex:1 1 320px; }
  body.hms-executive-ui .hms-field > :is(input,select,textarea) { width:100%; min-width:0; box-sizing:border-box; }

  /* These three registration screens share formGrid. The previous 980px
     breakpoint expanded every small field to a separate full-width row. */
  body.hms-executive-ui.hms-ui-density-compact .shell form.formGrid {
    grid-template-columns:repeat(auto-fit,minmax(min(100%,210px),1fr)) !important;
    gap:8px 10px !important; align-items:start;
  }
  body.hms-executive-ui.hms-ui-density-compact .shell form.formGrid > div { min-width:0; }
  body.hms-executive-ui.hms-ui-density-compact .shell form.formGrid :is(input,select) { box-sizing:border-box; max-width:100%; min-width:0; }

  /* Existing task/report/filter rows retain their field order and actions.
     Fixed content-sized bases stop the first field consuming the full row. */
  body.hms-executive-ui.hms-ui-density-compact .shell :is(.filter-bar,.phx-filters,.rx-filters) {
    flex-wrap:wrap !important; align-items:flex-end; gap:8px !important;
  }
  body.hms-executive-ui.hms-ui-density-compact .shell :is(.filter-bar,.phx-filters,.rx-filters) > .field {
    flex:0 1 230px !important; min-width:0 !important; max-width:100% !important;
  }
  body.hms-executive-ui.hms-ui-density-compact .shell :is(.filter-bar,.phx-filters,.rx-filters) > .field :is(input,select) {
    width:100%; min-width:0 !important; box-sizing:border-box;
  }
  body.hms-executive-ui.hms-ui-density-compact .shell .med-filter:not(.med-filter-patients) {
    grid-template-columns:repeat(auto-fit,minmax(min(100%,170px),230px)) !important;
    justify-content:start; gap:8px !important;
  }
  body.hms-executive-ui.hms-ui-density-compact :is(.os-invoice-fields,.hms-compact-field-grid) {
    display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr)) !important;
    gap:8px 10px !important;
  }
  body.hms-executive-ui.hms-ui-density-compact .os-toolbar > label { flex:0 1 auto; min-width:0; max-width:100%; }
  body.hms-executive-ui.hms-ui-density-compact .os-toolbar select { width:260px; min-width:0; max-width:100%; }
  body.hms-executive-ui.hms-ui-density-compact .dd-settings .dd-list-select { min-width:0; width:240px; max-width:100%; }

  /* Direct recently visited links occupy a bounded strip in the existing
     header. A horizontal scroll reveals longer names; no dropdown covers work. */
  #hms-recent-menu.hms-recent-screens { min-width:0; max-width:min(39vw,480px); flex:0 1 auto; }
  #hms-recent-menu[hidden] { display:none !important; }
  #hms-recent-list.hms-recent-screen-list { display:flex; align-items:center; gap:5px; overflow-x:auto; padding:3px 2px 5px; scrollbar-width:thin; overscroll-behavior-x:contain; }
  body.hms-executive-ui.hms-ui-density-compact #hms-recent-list .hms-recent-screen {
    display:inline-flex; flex:none; align-items:center; max-width:220px; white-space:nowrap;
    overflow:hidden; text-overflow:ellipsis; border:1px solid #d9c7aa; color:#61451f;
    background:linear-gradient(#fffdf8,#fff4df); text-decoration:none;
  }
  #hms-recent-list .hms-recent-screen > span { min-width:0; overflow:hidden; text-overflow:ellipsis; }
  #hms-recent-list .hms-recent-screen:focus-visible { outline:2px solid #946017; outline-offset:-2px; }
  body.hms-executive-ui.hms-ui-density-compact .global-shell-actions { min-width:0; flex:0 1 auto; }
  body.hms-executive-ui.hms-ui-density-compact .global-shell-actions > :is(a,button,.global-shell-notify) { flex-shrink:0; }
}
@media screen and (max-width:1100px) {
  #hms-recent-menu.hms-recent-screens { max-width:240px; }
}
@media screen and (max-width:700px) {
  body.hms-executive-ui.hms-ui-density-compact .global-shell-actions { flex-wrap:wrap; }
  #hms-recent-menu.hms-recent-screens { order:20; flex:1 0 100%; max-width:100%; }
  #hms-recent-list.hms-recent-screen-list { justify-content:flex-start; }
  body.hms-executive-ui.hms-ui-density-compact .shell :is(.filter-bar,.phx-filters,.rx-filters) { flex-direction:row !important; }
  body.hms-executive-ui.hms-ui-density-compact .shell :is(.filter-bar,.phx-filters,.rx-filters) > .field { flex:1 1 170px !important; }
}
@media print { #hms-recent-menu { display:none !important; } }
