/* Shared select/menu treatment and patient-library behavior for V9.2.6. */
.filters-toolbar {
  position: relative;
  z-index: 10;
}

.styled-dropdown {
  position: relative;
  min-width: 184px;
  color: var(--ink);
}
.styled-dropdown[open] { z-index: 32; }
.styled-dropdown > summary {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 13px;
  border: 1px solid var(--control);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
  transition: border-color .16s, box-shadow .16s, background .16s;
}
.styled-dropdown > summary::-webkit-details-marker { display: none; }
.styled-dropdown > summary:hover,
.styled-dropdown[open] > summary,
.styled-dropdown > summary:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 11%, transparent);
  outline: none;
}
.styled-dropdown > summary:focus-visible { border-color: var(--focus-ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 18%, transparent); }
.styled-dropdown > summary i {
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform .16s;
  flex: 0 0 auto;
}
.styled-dropdown[open] > summary i { transform: rotate(225deg) translate(-1px,-1px); }
.styled-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 7px);
  z-index: 34;
  width: max(100%, 220px);
  max-height: min(340px, 55dvh);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--control);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 14px 36px #202b3d24;
}
.styled-dropdown-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.styled-dropdown-option:hover,
.styled-dropdown-option:focus-visible { outline: none; background: var(--raised); }
.styled-dropdown-option[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.table-foot .styled-dropdown-option {
  border: 0;
  padding: 8px 10px;
  background: transparent;
  box-shadow: none;
}
.table-foot .styled-dropdown-option[aria-selected="true"] {
  background: var(--accent-soft);
}
.styled-dropdown-option .category-option-mark { position: relative; width: 16px; height: 16px; flex: 0 0 16px; color: var(--accent); }
.styled-dropdown-option[aria-selected="true"] .category-option-mark::before { content: ""; position: absolute; left: 5px; top: 2px; width: 5px; height: 9px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); }

/* The filter backdrop is a stacking context: lift that complete context above following cards. */
.table-panel { overflow: visible; }
.table-panel > .table-wrap { border-radius: var(--radius) var(--radius) 0 0; }
.patient-page-size-dropdown { min-width: 118px; }
.patient-page-size-dropdown > summary { min-height: 36px; padding-inline: 11px; font-size: 12px; }
.patient-page-size-dropdown .styled-dropdown-menu {
  top: auto;
  bottom: calc(100% + 7px);
  width: max(100%, 150px);
  min-width: 150px;
}
.pagination-buttons { gap: 8px; }
.table-foot .patient-page-size-dropdown { margin-left: 4px; }

/* Keep the patient search docked under the whole glass page header while scrolling. */
.patient-search-sticky {
  position: sticky;
  top: var(--patient-sticky-top, 140px);
  z-index: 24;
  transition: background-color .18s, border-color .18s, box-shadow .18s, backdrop-filter .18s;
}
.patient-search-sticky.is-stuck {
  background: var(--header-glass-fill);
  border-color: var(--header-edge);
  color: var(--header-ink);
  box-shadow: 0 16px 42px -24px var(--glass-shadow);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
}

@media (max-width: 660px) {
  .styled-dropdown { min-width: 0; }
  .styled-dropdown > summary { font-size: 13px; }
  .table-foot { flex-wrap: wrap; }
  .pagination-buttons { margin-left: auto; gap: 5px; }
  .patient-page-size-dropdown { min-width: 102px; }
  .patient-page-size-dropdown > summary { min-height: 34px; }
}

/* Patient library: a stationary glass filter card beside the independently scrolling results. */
.main-content.is-patient-view { display: flex; flex-direction: column; overflow: hidden; }
.is-patient-view .page-header { flex: 0 0 auto; }
.is-patient-view #connectionNotice { flex: 0 0 auto; }
.is-patient-view #pageContent { display: flex; flex: 1 1 auto; min-height: 0; padding-bottom: 0; overflow: hidden; }
.is-patient-view #pageFooter { display: none; }
.patient-library-layout { display: grid; grid-template-columns: minmax(250px, 300px) minmax(0, 1fr); align-items: stretch; gap: 18px; width: 100%; min-height: 0; }
.patient-filter-card { position: relative; display: flex; flex-direction: column; gap: 20px; min-height: 0; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 20px; background: var(--paper); border: 1px solid var(--line); }
.patient-filter-section { min-width: 0; }
.patient-filter-section h2 { margin: 0 0 10px; font-size: 12px; font-weight: 600; color: var(--ink); }
.patient-filter-card .search-field { width: 100%; min-width: 0; max-width: none; box-sizing: border-box; background: var(--raised); }
.patient-filter-card .search-field:focus-within { outline-color: var(--focus-ring); }
.patient-filter-card .search-field input { font-size: 12px; }
.patient-filter-choices { display: flex; flex-wrap: wrap; gap: 6px; }
.patient-filter-choice { min-height: 32px; padding: 5px 9px; border: 1px solid transparent; border-radius: 8px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }
.patient-filter-choice:hover { background: var(--active); color: var(--ink); }
.patient-filter-choice.is-selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.patient-date-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.patient-date-range label { display: grid; gap: 4px; color: var(--muted); font-size: 10px; }
.patient-date-range input { width: 100%; min-width: 0; padding: 7px 6px; font-size: 10px; background: var(--raised); }
.patient-export { width: 100%; margin-top: auto; }
.patient-filter-hint { color: var(--muted); font-size: 10px; }
.patient-list-column { min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.patient-list-column .table-panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.patient-list-column .member-rule-note { margin: 12px 4px 0; }
.patient-list-column .table-wrap { overflow-x: auto; overflow-y: visible; border-radius: var(--radius); }

@media (max-width: 820px) {
  .patient-library-layout { grid-template-columns: minmax(220px, 250px) minmax(0, 1fr); gap: 12px; }
  .patient-filter-card { padding: 16px; }
}
@media (max-width: 660px) {
  .main-content.is-patient-view { padding-bottom: 88px; }
  .patient-library-layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 37dvh) minmax(0, 1fr); gap: 10px; }
  .patient-filter-card { gap: 12px; padding: 13px; }
  .patient-filter-choices { gap: 5px; }
  .patient-filter-choice { min-height: 29px; padding: 4px 8px; font-size: 10px; }
  .patient-export { width: auto; align-self: flex-start; margin-top: 0; }
  .patient-filter-hint { display: none; }
  .patient-list-column .table-panel .panel-header { padding: 14px 14px 10px; }
  .patient-list-column .table-foot { padding: 10px 12px; }
}

/* Align the patient-library card bottoms with the desktop sidebar inset. */
@media (min-width: 661px) {
  .is-patient-view #pageContent { padding-bottom: 16px; }
}
@media (min-width: 661px) and (max-width: 1250px) {
  .is-patient-view #pageContent { padding-bottom: 12px; }
}
@media (min-width: 1900px) {
  .is-patient-view #pageContent { padding-bottom: 20px; }
}
