/* bc_historical_html — the Historical Bagging Checks popup.
 *
 * SCOPE. The form's three top-level nodes (the card and its two modal
 * overlays) are wrapped in one .bch-root div, because two or more top-level
 * nodes make Anvil keep its own wrapper as the root. .bch-root itself declares
 * nothing: this form is not a screen in the nav port, it is mounted into main's
 * content slot by px_form_alert and then moved into the modal overlay by
 * pxFormAlert, so the guide's screen-root rule (position/flex, drop
 * min-height) would change the popup's size. .bch-container keeps its own
 * height: 75vh, which is viewport-relative.
 *
 * WHAT IS NOT SCOPED ON THE ROOT, AND WHY. pxShowOverlay moves a
 * .px-modal-overlay into #px-modal-portal on open and pxHideOverlay puts it
 * back on a 300 ms timer, so both modals LEAVE .bch-root exactly while they
 * are visible. Every rule that styles something inside a modal is therefore
 * scoped on the private .bch-modal class the overlays carry, or written as a
 * compound on the element itself, never under :where(.bch-root). Rules for the
 * card (which never moves) are scoped :where(.bch-root), which adds zero
 * specificity and so cannot change which rule wins.
 *
 * HEAD-LINK ORDER. This asset is a head <link>, which loads before the
 * dependency's runtime theme injection and before theme.css ties are decided
 * by order. The five rules replacing inline style= sit on elements that also
 * carry a shared .px-grid-* or .px-modal class, so each carries a real second class
 * (.bch-root .bch-table-frame, .px-modal.bch-modal-body) at (0,2,0) rather
 * than relying on link order. Every other selector here is a private .bch-*
 * name that nothing else in either repo declares.
 *
 * DESIGNER GATE: none, deliberately. Nothing here is hidden until JavaScript
 * runs. #bch-loading-overlay ships with the `active` class in the markup and
 * the dependency's .px-loading-overlay rule is what shows it, so the canvas
 * shows exactly what the browser shows on first paint.
 */

:where(.bch-root) .bch-container {
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-subtle: rgba(59, 130, 246, 0.12);
  --bch-row-hover: rgba(59, 130, 246, 0.06);
  --bch-home-bg: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  --px-loading-accent: #3b82f6;
  font-family: var(--px-font);
  color: var(--px-text-primary);
  background: var(--px-bg-deep);
  position: relative;
  isolation: isolate;
  z-index: 0;
  height: 75vh;
}

/* [data-theme] sits on <html>, an ancestor of the root, so the scope goes
   between the two rather than in front of the whole selector. */
[data-theme="dark"] :where(.bch-root) .bch-container {
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --accent-subtle: rgba(96, 165, 250, 0.25);
  --bch-row-hover: rgba(96, 165, 250, 0.15);
  --bch-home-bg: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

:where(.bch-root) .bch-content {
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: pxFadeIn 0.4s ease;
  height: 100%;
  overflow: hidden;
}

:where(.bch-root) .bch-combobox {
  position: relative;
}

:where(.bch-root) .bch-combobox-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 250px;
  overflow-y: auto;
  background: var(--px-bg-card);
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  z-index: 100;
  display: none;
}

:where(.bch-root) .bch-combobox-list.active {
  display: block;
}

:where(.bch-root) .bch-combobox-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--px-text-primary);
  transition: background 0.1s;
}

:where(.bch-root) .bch-combobox-item:hover {
  background: var(--accent-subtle);
}

:where(.bch-root) .bch-combobox-empty {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--px-text-muted);
  font-style: italic;
}

:where(.bch-root) .bch-filters-card {
  background: var(--px-bg-card);
  border: 1px solid var(--px-border);
  border-radius: 12px;
  box-shadow: var(--px-shadow), var(--px-shadow-md);
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(200px, 1fr);
  gap: 16px;
}

:where(.bch-root) .bch-filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

:where(.bch-root) .bch-filter-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--px-text-muted);
}

:where(.bch-root) .bch-input {
  font-family: var(--px-font);
  font-size: 13px;
  padding: 10px 14px;
  border: 1px solid var(--px-border);
  border-radius: 8px;
  background: var(--px-input-bg);
  color: var(--px-text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

:where(.bch-root) .bch-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

:where(.bch-root) .bch-input::placeholder {
  color: var(--px-text-muted);
}

:where(.bch-root) .bch-row-notes {
  grid-column: 1 / -1;
  padding: 6px 4px 0;
  font-size: 12px;
  color: var(--px-text-muted);
  font-style: italic;
}

:where(.bch-root) .bch-row-notes strong {
  color: var(--px-text-secondary);
  font-style: normal;
}

:where(.bch-root) .bch-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

:where(.bch-root) .bch-badge-monthly {
  background: rgba(251, 191, 36, 0.2);
  color: #b45309;
}

:where(.bch-root) .bch-badge-acute {
  background: rgba(74, 222, 128, 0.2);
  color: #166534;
}

:where(.bch-root) .bch-badge-yes {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

:where(.bch-root) .bch-badge-no {
  background: rgba(100, 116, 139, 0.15);
  color: #64748b;
}

:where(.bch-root) .bch-badge-container {
  background: rgba(234, 179, 8, 0.18);
  color: #b45309;
  margin-left: 6px;
}

[data-theme="dark"] :where(.bch-root) .bch-badge-container {
  color: #fbbf24;
}

:where(.bch-root) .bch-action-btns {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

/* The reprint picker lives inside #bch-reprint-modal, which pxShowOverlay
   portals out of .bch-root on every open, so these three scope on the
   overlay's own private class. :where() keeps the (0,1,0) they have today. */
:where(.bch-modal) .bch-bag-select-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

:where(.bch-modal) .bch-bag-select-item {
  font: inherit;
  color: inherit;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--px-bg-elevated);
  border: 1px solid var(--px-border);
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s, background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

:where(.bch-modal) .bch-bag-select-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

:where(.bch-modal) .bch-bag-select-item:not(:disabled):hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

@media (max-width: 900px) {
  :where(.bch-root) .bch-content { padding: 16px; gap: 16px; }
  :where(.bch-root) .bch-filters-card { grid-template-columns: 1fr; }
  :where(.bch-root) .bch-action-btns { flex-wrap: wrap; }
}

@media (max-width: 600px) {
  :where(.bch-root) .bch-content { padding: 12px; gap: 12px; }
}

/* ------------------------------------------------------------------------
   Per-element rules on nodes that also carry a shared class.
   ------------------------------------------------------------------------ */

/* On .px-grid-card-frame, which theme.css declares at (0,1,0), so this rule
   names the root as a real ancestor and lands at (0,2,0). */
.bch-root .bch-table-frame {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* A bare div with no shared class; kept at (0,2,0) for consistency with the
   other three. */
.bch-root .bch-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--px-border);
  background: var(--px-bg-elevated);
}

/* On #bch-status-text. */
.bch-root .bch-status-text {
  font-size: 13px;
  color: var(--px-text-muted);
  font-style: italic;
}

/* On .px-grid-card, which theme.css declares with its own overflow and
   min-height at (0,1,0), a real tie this rule has to win. --px-grid-cols is
   the custom property theme.css's .px-grid-card rule reads. */
.bch-root .bch-table-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  --px-grid-cols: 100px 110px 70px 80px minmax(0,2fr) minmax(0,1.5fr) 60px 60px 130px 360px;
}

/* On the two .px-modal dialog boxes. Written
   as a compound on the element rather than under the root, because both modals
   are portaled out of .bch-root while they are open. (0,2,0) beats the
   dependency's own .px-modal, which is injected after every head link. */
.px-modal.bch-modal-body {
  max-width: 500px;
  width: 100%;
}
