/* =============================================================================
   OrganicSystem — Global selection popup / lookup list (UI reference: Product picker)
   One chrome for Farm / Product / Plot / Season / Year / Firm / Certificate / etc.
   Presentation only. Load AFTER os-popup-standard.css + os-dropdown-theme.css.
   ============================================================================= */

:root {
  --os-selection-popup-radius: var(--os-popup-radius, 0.5rem);
  --os-selection-popup-shadow: var(--os-popup-shadow, 0 12px 32px rgba(15, 23, 42, 0.18));
  --os-selection-popup-bg: var(--popup-bg, var(--os-color-popup, var(--os-surface)));
  --os-selection-popup-fg: var(--popup-text, var(--os-color-text, var(--os-text)));
  --os-selection-popup-border: var(--os-color-form-border, var(--os-color-border, var(--os-border)));
  --os-selection-popup-header-bg: var(--os-selection-popup-bg);
  --os-selection-popup-title-fg: var(--os-selection-popup-fg);
  --os-selection-popup-row-h: 30px;
  --os-selection-popup-header-h: 28px;
  --os-selection-popup-pad: 0;
  --os-selection-popup-z: 10050;
}

/* ---------- Alias legacy page markers → shared chrome ---------- */
.ags-product-balance-dropdown,
.ags-program-balance-popup,
.ags-plan-select-dropdown,
.ags-cert-file-select-dropdown,
.ags-harvest-popup-editor-dropdown,
.ags-harvest-details-popup,
[class*="-select-dropdown"],
[class*="-lookup-popup"],
[class*="-balance-popup"],
[class*="-balance-dropdown"] {
  /* Marker classes keep stacking / page hooks; visual rules live on .os-selection-popup */
}

.os-selection-popup.dx-overlay-wrapper,
.os-selection-popup.dx-overlay-wrapper.dx-popup-wrapper,
.ags-product-balance-dropdown.dx-overlay-wrapper,
.ags-program-balance-popup.dx-overlay-wrapper,
.ags-plan-select-dropdown.dx-overlay-wrapper,
.ags-cert-file-select-dropdown.dx-overlay-wrapper,
#ags-product-balance-lookup-popup-host .dx-overlay-wrapper,
#ags-program-balance-popup-host .dx-overlay-wrapper {
  z-index: var(--os-selection-popup-z) !important;
  pointer-events: auto !important;
  /* Isolate overlay paint from the page grid behind it. */
  contain: layout style;
}

.os-selection-popup .dx-overlay-shader,
.ags-product-balance-dropdown .dx-overlay-shader,
.ags-program-balance-popup .dx-overlay-shader {
  pointer-events: auto !important;
  contain: strict;
  transform: translateZ(0);
}

body.os-selection-popup-open .dx-datagrid,
body.os-selection-popup-open .dx-treelist {
  /* Avoid expensive grid repaints while a picker is open. */
  pointer-events: none;
}

/* Centered white modal shell */
.os-selection-popup > .dx-overlay-content,
.os-selection-popup .dx-overlay-content.dx-popup-normal,
.ags-product-balance-dropdown > .dx-overlay-content,
.ags-program-balance-popup > .dx-overlay-content,
.ags-plan-select-dropdown > .dx-overlay-content,
.ags-cert-file-select-dropdown > .dx-overlay-content {
  background-color: var(--os-selection-popup-bg) !important;
  color: var(--os-selection-popup-fg) !important;
  border: 1px solid var(--os-selection-popup-border) !important;
  border-radius: var(--os-selection-popup-radius) !important;
  box-shadow: var(--os-selection-popup-shadow) !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

/* In-grid attached SelectBox lists — compact, no modal chrome */
.os-selection-popup--attached.dx-overlay-wrapper,
.os-selection-popup--attached.dx-dropdowneditor-overlay {
  z-index: var(--os-selection-popup-z) !important;
}

.os-selection-popup--attached > .dx-overlay-content,
.os-selection-popup--attached .dx-overlay-content {
  background-color: var(--os-selection-popup-bg) !important;
  color: var(--os-selection-popup-fg) !important;
  border: 1px solid var(--os-selection-popup-border) !important;
  border-radius: var(--os-selection-popup-radius) !important;
  box-shadow: var(--os-selection-popup-shadow) !important;
  min-width: 160px !important;
  max-width: min(420px, calc(100vw - 16px)) !important;
  max-height: min(320px, calc(100vh - 16px)) !important;
  overflow: hidden !important;
}

.os-selection-popup--attached .dx-popup-title,
.os-selection-popup--attached .dx-toolbar.dx-popup-title {
  display: none !important;
}

.os-selection-popup--attached .dx-popup-content {
  padding: 0 !important;
}

/* Title top-left + close top-right */
.os-selection-popup .dx-popup-title,
.ags-product-balance-dropdown .dx-popup-title,
.ags-program-balance-popup .dx-popup-title,
.ags-plan-select-dropdown .dx-popup-title,
.ags-cert-file-select-dropdown .dx-popup-title {
  background-color: var(--os-selection-popup-header-bg) !important;
  color: var(--os-selection-popup-title-fg) !important;
  border-bottom: 1px solid var(--os-selection-popup-border) !important;
  min-height: 44px !important;
  padding: 0 0.75rem !important;
  box-sizing: border-box !important;
}

.os-selection-popup .dx-popup-title .dx-toolbar-label,
.os-selection-popup .dx-popup-title .dx-toolbar-label .dx-toolbar-item-content,
.ags-product-balance-dropdown .dx-popup-title .dx-toolbar-label,
.ags-program-balance-popup .dx-popup-title .dx-toolbar-label,
.ags-plan-select-dropdown .dx-popup-title .dx-toolbar-label,
.ags-cert-file-select-dropdown .dx-popup-title .dx-toolbar-label {
  color: var(--os-selection-popup-title-fg) !important;
  font-weight: 600 !important;
  font-size: 0.95rem !important;
  text-align: start !important;
}

.os-selection-popup .dx-popup-title .dx-closebutton,
.os-selection-popup .dx-popup-title .dx-button.dx-closebutton,
.ags-product-balance-dropdown .dx-popup-title .dx-closebutton,
.ags-program-balance-popup .dx-popup-title .dx-closebutton {
  margin-inline-start: auto !important;
}

.os-selection-popup .dx-popup-title .dx-closebutton .dx-icon,
.ags-product-balance-dropdown .dx-popup-title .dx-closebutton .dx-icon,
.ags-program-balance-popup .dx-popup-title .dx-closebutton .dx-icon {
  color: var(--os-selection-popup-title-fg) !important;
  opacity: 0.85;
}

/* Content: flex column; table owns scroll (not outer popup) */
.os-selection-popup .dx-popup-content,
.ags-product-balance-dropdown .dx-popup-content,
.ags-program-balance-popup .dx-popup-content,
.ags-plan-select-dropdown .dx-popup-content,
.ags-cert-file-select-dropdown .dx-popup-content,
#ags-product-balance-lookup-popup-host .dx-popup-content,
#ags-program-balance-popup-host .dx-popup-content {
  padding: var(--os-selection-popup-pad) !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  background-color: var(--os-selection-popup-bg) !important;
  color: var(--os-selection-popup-fg) !important;
}

/* Search (when present) — top of list, consistent */
.os-selection-popup .dx-list-search,
.os-selection-popup .dx-dropdowneditor-search,
.ags-plan-select-dropdown .dx-list-search,
.ags-cert-file-select-dropdown .dx-list-search {
  flex: 0 0 auto !important;
  margin: 0.5rem 0.65rem 0.35rem !important;
  padding: 0 !important;
}

.os-selection-popup .dx-list-search .dx-texteditor,
.os-selection-popup .dx-list-search .dx-texteditor-input,
.ags-plan-select-dropdown .dx-list-search .dx-texteditor,
.ags-plan-select-dropdown .dx-list-search .dx-texteditor-input,
.ags-cert-file-select-dropdown .dx-list-search .dx-texteditor,
.ags-cert-file-select-dropdown .dx-list-search .dx-texteditor-input {
  min-height: 36px !important;
  background-color: var(--os-color-form-control-bg, var(--os-selection-popup-bg)) !important;
  color: var(--os-color-input-text, var(--os-selection-popup-fg)) !important;
  border-color: var(--os-selection-popup-border) !important;
}

/* Grid / list fill popup body */
.os-selection-popup .dx-popup-content .dx-datagrid,
.os-selection-popup .dx-popup-content .dx-list,
.os-selection-popup .os-selection-popup-grid,
.ags-product-balance-dropdown .dx-popup-content .dx-datagrid,
.ags-program-balance-popup .dx-popup-content .dx-datagrid,
.ags-plan-select-dropdown .dx-popup-content .dx-list,
.ags-cert-file-select-dropdown .dx-popup-content .dx-list,
#ags-product-balance-lookup-popup-host .dx-popup-content .dx-datagrid {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  max-height: 100% !important;
  width: 100% !important;
  overflow: hidden !important;
  background-color: var(--os-selection-popup-bg) !important;
  color: var(--os-selection-popup-fg) !important;
  border-color: var(--os-selection-popup-border) !important;
}

/* Hide chrome that competes with the picker table */
.os-selection-popup .dx-datagrid-pager,
.os-selection-popup .dx-datagrid-header-panel,
.os-selection-popup .dx-datagrid-filter-row,
.os-selection-popup .dx-header-filter,
.os-selection-popup .dx-header-filter-indicator,
.os-selection-popup .dx-datagrid-headers .dx-column-indicators,
.ags-product-balance-dropdown .dx-datagrid-pager,
.ags-product-balance-dropdown .dx-datagrid-header-panel,
.ags-product-balance-dropdown .dx-datagrid-filter-row,
.ags-product-balance-dropdown .dx-header-filter,
.ags-product-balance-dropdown .dx-header-filter-indicator,
.ags-product-balance-dropdown .dx-datagrid-headers .dx-column-indicators,
.ags-program-balance-popup .dx-datagrid-pager,
.ags-program-balance-popup .dx-datagrid-header-panel,
.ags-program-balance-popup .dx-datagrid-filter-row {
  display: none !important;
}

/* Sticky header band; body scrolls underneath */
.os-selection-popup .dx-datagrid-headers,
.ags-product-balance-dropdown .dx-datagrid-headers,
.ags-program-balance-popup .dx-datagrid-headers {
  overflow-x: hidden !important;
  flex: 0 0 auto !important;
  background-color: var(--os-color-grid-header, var(--os-selection-popup-bg)) !important;
  color: var(--os-color-grid-header-text, var(--os-selection-popup-fg)) !important;
  border-color: var(--os-color-grid-border, var(--os-selection-popup-border)) !important;
  border-bottom: 1px solid var(--os-color-grid-border, var(--os-selection-popup-border)) !important;
}

.os-selection-popup .dx-datagrid-headers .dx-header-row > td,
.ags-product-balance-dropdown .dx-datagrid-headers .dx-header-row > td,
.ags-program-balance-popup .dx-datagrid-headers .dx-header-row > td {
  background-color: var(--os-color-grid-header, var(--os-selection-popup-bg)) !important;
  color: var(--os-color-grid-header-text, var(--os-selection-popup-fg)) !important;
  border-color: var(--os-color-grid-border, var(--os-selection-popup-border)) !important;
  height: var(--os-selection-popup-header-h) !important;
  vertical-align: middle !important;
  padding-top: 0.35rem !important;
  padding-bottom: 0.35rem !important;
}

.os-selection-popup .dx-datagrid-headers .dx-header-row > td .dx-datagrid-text-content,
.ags-product-balance-dropdown .dx-datagrid-headers .dx-header-row > td .dx-datagrid-text-content,
.ags-program-balance-popup .dx-datagrid-headers .dx-header-row > td .dx-datagrid-text-content {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100% !important;
  max-width: 100% !important;
  color: var(--os-color-grid-header-text, var(--os-selection-popup-fg)) !important;
  visibility: visible !important;
  opacity: 1 !important;
  font-weight: 600;
}

/* Scroll inside rowsview / list — never clip the scrollport */
.os-selection-popup .dx-datagrid-rowsview,
.ags-product-balance-dropdown .dx-datagrid-rowsview,
.ags-program-balance-popup .dx-datagrid-rowsview {
  overflow: hidden !important;
  min-height: 0 !important;
}

.os-selection-popup .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
.ags-product-balance-dropdown .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
.ags-program-balance-popup .dx-datagrid-rowsview.dx-scrollable-native .dx-scrollable-container,
.os-selection-popup .dx-list .dx-scrollable-native .dx-scrollable-container,
.ags-plan-select-dropdown .dx-list .dx-scrollable-native .dx-scrollable-container,
.ags-cert-file-select-dropdown .dx-list .dx-scrollable-native .dx-scrollable-container {
  overflow-x: auto !important;
  overflow-y: auto !important;
}

.os-selection-popup .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
.ags-product-balance-dropdown .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container,
.ags-program-balance-popup .dx-datagrid-rowsview.dx-scrollable-simulated .dx-scrollable-container {
  overflow: hidden !important;
}

.os-selection-popup .dx-scrollable-scrollbar,
.ags-product-balance-dropdown .dx-scrollable-scrollbar,
.ags-program-balance-popup .dx-scrollable-scrollbar {
  pointer-events: auto !important;
  z-index: 5;
}

.os-selection-popup .dx-datagrid-rowsview .dx-scrollable-content,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-scrollable-content {
  padding-bottom: 4px;
}

/* Consistent row geometry + selection affordance */
.os-selection-popup .dx-datagrid-rowsview .dx-data-row > td,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-data-row > td,
.ags-program-balance-popup .dx-datagrid-rowsview .dx-data-row > td {
  height: var(--os-selection-popup-row-h) !important;
  min-height: var(--os-selection-popup-row-h) !important;
  max-height: none !important;
  vertical-align: middle !important;
  padding-top: var(--os-list-item-padding-y, 0.2rem) !important;
  padding-bottom: var(--os-list-item-padding-y, 0.2rem) !important;
  background-color: var(--os-color-grid-body, var(--os-selection-popup-bg)) !important;
  color: var(--os-color-text, var(--os-selection-popup-fg)) !important;
  border-color: var(--os-color-grid-border, var(--os-selection-popup-border)) !important;
  cursor: pointer;
}

.os-selection-popup .dx-datagrid-rowsview .dx-data-row > td .dx-datagrid-text-content,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-data-row > td .dx-datagrid-text-content,
.ags-program-balance-popup .dx-datagrid-rowsview .dx-data-row > td .dx-datagrid-text-content {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--os-color-text, var(--os-color-input-text)) !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.os-selection-popup .dx-datagrid-rowsview .dx-data-row:hover > td,
.os-selection-popup .dx-datagrid-rowsview .dx-row-focused > td,
.os-selection-popup .dx-datagrid-rowsview .dx-selection > td,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-data-row:hover > td,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-row-focused > td,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-selection > td,
.ags-program-balance-popup .dx-datagrid-rowsview .dx-data-row:hover > td,
.ags-program-balance-popup .dx-datagrid-rowsview .dx-selection > td {
  background-color: var(--os-popup-selection-hover-bg) !important;
  color: var(--os-selection-popup-fg) !important;
}

/* List-based pickers (Farm / Plot / Season / Year / Cert …) */
.os-selection-popup .dx-list,
.ags-plan-select-dropdown .dx-list,
.ags-cert-file-select-dropdown .dx-list {
  background-color: var(--os-selection-popup-bg) !important;
  color: var(--os-selection-popup-fg) !important;
  border: none !important;
}

.os-selection-popup .dx-list .dx-list-item,
.ags-plan-select-dropdown .dx-list .dx-list-item,
.ags-cert-file-select-dropdown .dx-list .dx-list-item {
  min-height: var(--os-selection-popup-row-h) !important;
  padding-top: var(--os-list-item-padding-y, 0.2rem) !important;
  padding-bottom: var(--os-list-item-padding-y, 0.2rem) !important;
  border-color: var(--os-selection-popup-border) !important;
  color: var(--os-selection-popup-fg) !important;
  background-color: transparent !important;
  cursor: pointer;
}

.os-selection-popup .dx-list .dx-list-item .dx-list-item-content,
.ags-plan-select-dropdown .dx-list .dx-list-item-content,
.ags-cert-file-select-dropdown .dx-list .dx-list-item-content {
  line-height: 1.3 !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit !important;
}

.os-selection-popup .dx-list .dx-list-item.dx-state-hover,
.os-selection-popup .dx-list .dx-list-item.dx-state-focused,
.os-selection-popup .dx-list .dx-list-item.dx-list-item-selected,
.ags-plan-select-dropdown .dx-list .dx-list-item.dx-state-hover,
.ags-plan-select-dropdown .dx-list .dx-list-item.dx-list-item-selected,
.ags-cert-file-select-dropdown .dx-list .dx-list-item:hover,
.ags-cert-file-select-dropdown .dx-list .dx-list-item.dx-state-focused,
.ags-cert-file-select-dropdown .dx-list .dx-list-item.dx-list-item-selected {
  background-color: var(--os-popup-selection-hover-bg) !important;
  color: var(--os-selection-popup-fg) !important;
}

/* Kill stuck virtual-row skeletons inside pickers */
.os-selection-popup .dx-virtual-row,
.os-selection-popup .dx-virtual-row > td,
.ags-product-balance-dropdown .dx-virtual-row,
.ags-product-balance-dropdown .dx-virtual-row > td,
.ags-program-balance-popup .dx-virtual-row,
.ags-program-balance-popup .dx-virtual-row > td,
#ags-product-balance-lookup-popup-host .dx-virtual-row,
#ags-product-balance-lookup-popup-host .dx-virtual-row > td {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: none !important;
  background: none !important;
  background-image: none !important;
}

/* Popup host anchors (DX mounts overlay inside) */
#ags-product-balance-lookup-popup-host,
#ags-program-balance-popup-host {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  overflow: visible;
  z-index: var(--os-selection-popup-z);
}

#productPopupGrid,
.ags-product-balance-lookup-grid,
.os-selection-popup-grid {
  width: 100%;
  min-height: 160px;
  max-width: 100%;
}

/* Touch / tablet comfort — still within compact range */
@media (max-width: 1024px) {
  :root {
    --os-selection-popup-row-h: 32px;
    --os-selection-popup-header-h: 30px;
  }

  .os-selection-popup > .dx-overlay-content,
  .ags-product-balance-dropdown > .dx-overlay-content,
  .ags-program-balance-popup > .dx-overlay-content {
    max-width: calc(100vw - 24px) !important;
  }
}

@media (max-width: 640px) {
  .os-selection-popup > .dx-overlay-content,
  .ags-product-balance-dropdown > .dx-overlay-content,
  .ags-program-balance-popup > .dx-overlay-content,
  .ags-plan-select-dropdown > .dx-overlay-content {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
  }
}

/* Pointer events for clickable grid cells inside Product picker */
.os-selection-popup .dx-overlay-content,
.os-selection-popup .dx-popup-content,
.os-selection-popup .dx-datagrid,
.os-selection-popup .dx-datagrid-rowsview,
.os-selection-popup .dx-datagrid-rowsview .dx-data-row,
.os-selection-popup .dx-datagrid-rowsview .dx-data-row > td,
.ags-product-balance-dropdown .dx-overlay-content,
.ags-product-balance-dropdown .dx-popup-content,
.ags-product-balance-dropdown .dx-datagrid,
.ags-product-balance-dropdown .dx-datagrid-rowsview,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-data-row,
.ags-product-balance-dropdown .dx-datagrid-rowsview .dx-data-row > td {
  pointer-events: auto !important;
}
