.filter-bar {
    overflow: visible;
    position: relative;
    z-index: 20;
}

.filter-bar .filter-group:has(.custom-dropdown) {
    min-width: 160px;
}

.custom-dropdown {
    position: relative;
    width: 100%;
}

.custom-dropdown-trigger {
    width: 100%;
    padding: 0 30px 0 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 13px;
    font-family: inherit;
    background: #f8fafc;
    cursor: pointer;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    transition: border-color .2s, background .2s;
    outline: none;
    box-sizing: border-box;
    height: 40px;
    line-height: 1.25;
    display: flex;
    align-items: center;
    min-width: 0;
}

.custom-dropdown-trigger .cd-trigger-label {
    display: block;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-dropdown-trigger::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: #1a6b3c;
    pointer-events: none;
    transition: transform .2s ease;
}

.custom-dropdown-trigger.open::after {
    transform: translateY(-50%) rotate(180deg);
}

.custom-dropdown-trigger:hover:not(.is-placeholder),
.custom-dropdown-trigger.open {
    border-color: #1a6b3c;
    background: #fff;
}

.custom-dropdown-trigger.is-placeholder:not(.open):hover {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.custom-dropdown-trigger.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.custom-dropdown-trigger-input {
    cursor: text;
    color: #1e293b;
}

.custom-dropdown:has(select option:disabled:checked) .custom-dropdown-trigger:not(.open),
.custom-dropdown-trigger.is-placeholder:not(.open),
.custom-dropdown-trigger-input.is-placeholder:not(.open) {
    color: #94a3b8;
}

.filter-bar .custom-dropdown-trigger:not(.is-placeholder),
.filter-bar .custom-dropdown-trigger-input:not(.is-placeholder) {
    background: #fff;
    color: #1e293b;
}

.filter-bar .custom-dropdown-trigger.is-placeholder:not(.open),
.filter-bar .custom-dropdown-trigger-input.is-placeholder:not(.open) {
    background: #f8fafc;
    color: #94a3b8;
}

.custom-dropdown-trigger-input.open,
.custom-dropdown-trigger-input:focus:not(.is-placeholder) {
    color: #1e293b;
}

.custom-dropdown-trigger-input:focus:not(.is-placeholder) {
    border-color: #1a6b3c;
    background: #fff;
}

.custom-dropdown-trigger-input.is-disabled {
    cursor: not-allowed;
    background: #f8fafc;
}

.custom-dropdown-trigger-wrap {
    position: relative;
}

.custom-dropdown-trigger-wrap::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: #1a6b3c;
    pointer-events: none;
    transition: transform .2s;
}

.custom-dropdown-trigger-wrap:has(.custom-dropdown-trigger-input.open)::after {
    transform: translateY(-50%) rotate(180deg);
}

.custom-dropdown:has(.custom-dropdown-select.is-invalid) .custom-dropdown-trigger {
    border-color: #dc2626;
}

.custom-dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    max-height: 220px;
    overflow-y: auto;
    display: none;
    z-index: 9999;
    box-shadow: 0 8px 24px rgba(26, 107, 60, 0.12);
}

.custom-dropdown-list.show {
    display: block;
}

.custom-dropdown-list.cd-floating {
    position: fixed;
    z-index: 10750;
    right: auto;
    margin-top: 0;
}

.custom-dropdown-list .cd-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    transition: background .1s, color .1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-dropdown-list.cd-two-line-items .cd-item {
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.custom-dropdown-list .cd-item:last-child {
    border-bottom: none;
}

.custom-dropdown-list .cd-item:hover,
.custom-dropdown-list .cd-item.selected {
    background: #f0fdf4;
    color: #1a6b3c;
    font-weight: 600;
}

.custom-dropdown-list .cd-item.active {
    background: #e7f7ec;
    color: #1a6b3c;
}

.custom-dropdown-list .cd-item .cd-mark {
    background: #fef08a;
    color: #1a1a2e;
    border-radius: 2px;
    padding: 0 1px;
}

.custom-dropdown-list .cd-item.cd-empty,
.custom-dropdown-list .cd-item.cd-empty:hover {
    color: #94a3b8;
    font-weight: 400;
    cursor: default;
    background: #fff;
    pointer-events: none;
}

.custom-dropdown-list .cd-search {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    position: sticky;
    top: 0;
    background: #fff;
    border-radius: 10px 10px 0 0;
}

.custom-dropdown-list .cd-search:focus {
    border-bottom-color: #1a6b3c;
}

select.custom-dropdown-select {
    display: none !important;
}

.custom-date-separator {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 500;
    flex-shrink: 0;
}

[id^="customDateGroup"] {
    align-items: center;
    gap: 8px;
}

/* Table pagination page selector — compact custom dropdown (5 visible rows, then scroll) */
.pagination-page-select .custom-dropdown,
.pagination-page-select.pagination-page-dropdown {
    width: auto;
    min-width: 70px;
}

.pagination-page-select .custom-dropdown-trigger {
    display: block !important;
    width: 100%;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    padding: 0 28px 0 10px !important;
    border-radius: 8px;
    font-size: 13px !important;
    font-weight: 600;
    line-height: 36px !important;
    text-align: center;
    box-sizing: border-box !important;
    overflow: hidden;
    white-space: nowrap;
}

.pagination-page-select .custom-dropdown-trigger::after {
    position: absolute !important;
    right: 10px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    line-height: 1 !important;
    color: #1a1a2e !important;
    transition: transform .2s ease !important;
}

.pagination-page-select .custom-dropdown-trigger.open::after {
    transform: translateY(-50%) rotate(180deg) !important;
}

.custom-dropdown-list.is-page-select {
    max-height: calc(40px * 5);
}

/* Pagination sits at the bottom of tables — open upward so the menu
   does not extend the document and trigger a page scrollbar. */
.pagination-page-select .custom-dropdown-list,
.pagination-page-select .custom-dropdown-list.is-page-select {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 4px;
}

.table-pagination-wrap .pagination-page-select {
    position: relative;
    z-index: 30;
}

/* Dark mode — loaded after light styles on patient portal pages */
html[data-theme="dark"] .custom-dropdown-trigger,
html[data-theme="dark"] .custom-dropdown-trigger-input {
    background: var(--dm-surface-raised, #2c2c30) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .custom-dropdown-trigger::after,
html[data-theme="dark"] .custom-dropdown-trigger-wrap::after {
    color: #fff !important;
}

html[data-theme="dark"] .custom-dropdown-trigger:not(.is-placeholder),
html[data-theme="dark"] .custom-dropdown-trigger-input:not(.is-placeholder),
html[data-theme="dark"] .filter-bar .custom-dropdown-trigger:not(.is-placeholder),
html[data-theme="dark"] .filter-bar .custom-dropdown-trigger-input:not(.is-placeholder),
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger:not(.is-placeholder),
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger-input:not(.is-placeholder) {
    background: var(--dm-bg, #1c1c1e) !important;
    color: var(--dm-text, #f5f5f5) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
}

html[data-theme="dark"] .custom-dropdown-trigger.is-placeholder:not(.open),
html[data-theme="dark"] .custom-dropdown-trigger-input.is-placeholder:not(.open),
html[data-theme="dark"] .filter-bar .custom-dropdown-trigger.is-placeholder:not(.open),
html[data-theme="dark"] .filter-bar .custom-dropdown-trigger-input.is-placeholder:not(.open),
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger.is-placeholder:not(.open),
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger-input.is-placeholder:not(.open) {
    background: var(--dm-surface-raised, #2c2c30) !important;
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .custom-dropdown-trigger:hover:not(.is-placeholder),
html[data-theme="dark"] .custom-dropdown-trigger.open,
html[data-theme="dark"] .custom-dropdown-trigger-input.open,
html[data-theme="dark"] .custom-dropdown-trigger-input:focus:not(.is-placeholder),
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger:hover:not(.is-placeholder),
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger.open {
    border-color: var(--dm-primary, #1a6b3c) !important;
    background: var(--dm-bg, #1c1c1e) !important;
    color: var(--dm-text, #f5f5f5) !important;
    box-shadow: none !important;
}

html[data-theme="dark"] .custom-dropdown-trigger.is-placeholder:not(.open):hover,
html[data-theme="dark"] .prescription-filters-row .custom-dropdown-trigger.is-placeholder:not(.open):hover {
    border-color: var(--dm-border, #3a3a3f) !important;
    background: var(--dm-surface-raised, #2c2c30) !important;
}

html[data-theme="dark"] .custom-dropdown-list {
    background: var(--dm-surface, #242428) !important;
    border-color: var(--dm-border, #3a3a3f) !important;
    box-shadow: none !important;
}

html[data-theme="dark"] .custom-dropdown-list .cd-item {
    color: var(--dm-text, #f5f5f5) !important;
    border-bottom-color: var(--dm-border, #3a3a3f) !important;
}

html[data-theme="dark"] .custom-dropdown-list .cd-item:hover,
html[data-theme="dark"] .custom-dropdown-list .cd-item.selected,
html[data-theme="dark"] .custom-dropdown-list .cd-item.active {
    background: var(--dm-primary-subtle, rgba(26, 107, 60, 0.18)) !important;
    color: #4ade80 !important;
}

html[data-theme="dark"] .custom-dropdown-list .cd-item.cd-empty,
html[data-theme="dark"] .custom-dropdown-list .cd-item.cd-empty:hover {
    background: var(--dm-surface, #242428) !important;
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .custom-dropdown-list .cd-item .cd-mark {
    background: rgba(250, 204, 21, 0.35) !important;
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .custom-dropdown-list .cd-search {
    background: var(--dm-surface, #242428) !important;
    border-bottom-color: var(--dm-border, #3a3a3f) !important;
    color: var(--dm-text, #f5f5f5) !important;
}

html[data-theme="dark"] .custom-dropdown-list .cd-search:focus {
    border-bottom-color: var(--dm-primary, #1a6b3c) !important;
}

html[data-theme="dark"] .custom-date-separator {
    color: var(--dm-text-secondary, #a1a1aa) !important;
}

html[data-theme="dark"] .pagination-page-select .custom-dropdown-trigger::after {
    color: var(--dm-text-secondary, #a1a1aa) !important;
}
