/* Purchase-order list: keep the filters available without sacrificing list space. */
body #po-list-layout,
body #po-list-layout:not(.po-filters-collapsed) {
  display: block !important;
  height: auto !important;
  max-height: none !important;
  grid-template-columns: none !important;
}
body #po-list-layout > .po-list-content { width: 100%; min-width: 0; }
body #po-list-layout.po-filters-collapsed > #po-filter-panel { display: none !important; }
body #po-list-layout:not(.po-filters-collapsed) > #po-filter-panel {
  display: block !important;
  position: fixed !important;
  z-index: 12002;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(430px, 100vw) !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  box-shadow: 16px 0 48px #0008;
  padding-bottom: 84px;
}
body .po-filter-backdrop:not([hidden]) {
  display: block !important;
  position: fixed;
  inset: 0;
  z-index: 12001;
  width: 100%;
  height: 100%;
  border: 0;
  background: #0009;
}
body #po-filter-backdrop[hidden] { display: none !important; }
body.po-filter-drawer-open { overflow: hidden !important; }
body #po-filter-panel .po-filter-sidebar-header {
  position: sticky !important;
  top: 0;
  z-index: 4;
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center;
  background: var(--second-bg-color);
}
body #po-filter-panel .po-filter-sidebar-header > div { flex: 1; min-width: 0; }
body #po-filter-panel .po-filter-sidebar-header > button { flex: 0 0 auto !important; width: auto !important; }
body #po-filter-panel .po-filter-close { margin-left: 4px; min-width: 40px; min-height: 40px; font-size: 22px; }
body #po-filter-panel .po-filter-footer {
  position: sticky;
  bottom: -84px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom));
  background: var(--second-bg-color);
  border-top: 1px solid var(--border-color);
}
body #po-filter-panel .po-filter-footer button { min-height: 44px; }
body .po-row-detail-toggle { display: none; }

/* Desktop filters belong beside the list; the list table must not flex to zero. */
body #po-list-layout > .po-list-content > .purchase-orders-summary {
  flex: 0 0 auto !important;
  height: clamp(400px, calc(100dvh - 300px), 900px) !important;
  min-height: 400px !important;
  overflow: auto !important;
}

@media (min-width: 1301px) and (pointer: fine) {
  body #po-list-layout:not(.po-filters-collapsed) {
    display: grid !important;
    grid-template-columns: 300px minmax(0, 1fr) !important;
    align-items: start;
    gap: 24px;
  }
  body #po-list-layout:not(.po-filters-collapsed) > #po-filter-panel {
    position: sticky !important;
    z-index: 1;
    top: 12px;
    bottom: auto;
    box-sizing: border-box;
    min-width: 0;
    width: 100% !important;
    height: calc(100dvh - 110px) !important;
    max-height: calc(100dvh - 110px) !important;
    padding-bottom: 12px;
    box-shadow: none;
  }
  body #po-filter-backdrop:not([hidden]) { display: none !important; }
  body.po-filter-drawer-open { overflow: auto !important; }
  body #po-filter-panel .po-filter-footer,
  body #po-filter-panel .po-filter-close { display: none !important; }
  body #po-list-layout .purchase-orders-summary { overflow-x: auto; }
  body #po-list-layout .purchase-orders-summary-table { min-width: 1540px; width: 100%; font-size: 13px; }
  body #po-list-layout .purchase-orders-summary-table thead td,
  body #po-list-layout .purchase-orders-summary-table tbody td { padding: 9px 8px; line-height: 1.35; }
}

@media (max-width: 1300px), (pointer: coarse) {
  body #po-list-layout:not(.po-filters-collapsed) > #po-filter-panel {
    position: fixed !important;
    top: 0;
    bottom: 0;
    max-height: 100dvh !important;
    overflow-y: auto !important;
  }
  body #po-list-layout table.mobile-card-table > tbody > tr.po-list-row {
    position: relative;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px 8px;
    padding: 10px;
  }
  body #po-list-layout table.mobile-card-table > tbody > tr.po-list-row > td { padding: 3px 5px !important; }
  body #po-list-layout table.mobile-card-table > tbody > tr.po-list-row > td.po-list-select {
    position: absolute !important;
    top: 13px;
    left: 8px;
    width: 24px !important;
    z-index: 1;
  }
  body #po-list-layout .po-list-row > td.po-list-select::before,
  body #po-list-layout .po-list-row > td.po-list-number::before,
  body #po-list-layout .po-list-row > td.po-list-money::before { display: none !important; }
  body #po-list-layout table.mobile-card-table > tbody > tr.po-list-row > td.po-list-number { order: 1; padding-left: 32px !important; font-size: 16px; font-weight: 750; }
  body #po-list-layout .po-list-row > td.po-list-money { order: 2; text-align: right; align-items: flex-end !important; font-weight: 750; }
  body #po-list-layout .po-list-row > td.po-list-vendor { order: 3; grid-column: 1 / -1; font-weight: 700; font-size: 14px; }
  body #po-list-layout .po-list-row > td:nth-child(3) { order: 4; }
  body #po-list-layout .po-list-row > td:nth-child(4) { order: 5; }
  body #po-list-layout .po-list-row > td:nth-child(5) { order: 6; }
  body #po-list-layout .po-list-row > td:nth-child(9) { order: 7; }
  body #po-list-layout .po-list-row > td:nth-child(14) { order: 8; }
  body #po-list-layout .po-list-row > td.po-list-action { order: 10; grid-column: 1 / -1; }
  body #po-list-layout .po-list-row:not(.po-row-expanded) > td:nth-child(7),
  body #po-list-layout .po-list-row:not(.po-row-expanded) > td:nth-child(8),
  body #po-list-layout .po-list-row:not(.po-row-expanded) > td:nth-child(10),
  body #po-list-layout .po-list-row:not(.po-row-expanded) > td:nth-child(11),
  body #po-list-layout .po-list-row:not(.po-row-expanded) > td:nth-child(12),
  body #po-list-layout .po-list-row:not(.po-row-expanded) > td:nth-child(15) { display: none !important; }
  body #po-list-layout .po-list-row.po-row-expanded > td:nth-child(7),
  body #po-list-layout .po-list-row.po-row-expanded > td:nth-child(8),
  body #po-list-layout .po-list-row.po-row-expanded > td:nth-child(10),
  body #po-list-layout .po-list-row.po-row-expanded > td:nth-child(11),
  body #po-list-layout .po-list-row.po-row-expanded > td:nth-child(12),
  body #po-list-layout .po-list-row.po-row-expanded > td:nth-child(15) { order: 11; }
  body #po-list-layout .po-row-detail-toggle {
    display: inline-block;
    width: fit-content;
    min-height: 32px;
    padding: 4px 0;
    border: 0;
    background: transparent;
    color: var(--accent-color);
    font-size: 12px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
  }
  body #po-list-layout .po-list-row > td.po-list-action .po-status-action { width: 100%; }
}

@media (max-width: 700px) {
  body #po-list-layout:not(.po-filters-collapsed) > #po-filter-panel {
    top: auto !important;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100vw !important;
    height: min(88dvh, 820px) !important;
    max-height: 88dvh !important;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -16px 48px #0009;
  }
}
