/* Shared searchable select compatibility layer.
   Main styles for SearchableSelect dropdown functionality.
   Table/form-specific fixes are in form_components.css */

/* Base wrapper - ensures proper positioning */
.searchable-select,
.tpgc-searchable-select {
  position: relative !important;
  display: inline-block !important;
  width: 100% !important;
}

/* Ensure dropdown menu is properly positioned */
.searchable-select .dropdown-menu,
.tpgc-searchable-select .dropdown-menu {
  width: 100% !important;
  min-width: 280px !important;
}

/* Dropdown panel - clean styling without blur */
.dropdown-menu.ss-menu-panel,
.ss-portal-menu {
  /* width: 100% !important; */
  min-width: 280px !important;
  max-width: 500px !important;
  overflow-y: auto !important;
  box-sizing: border-box !important;
  padding: 0.5rem !important;
  border: 1px solid rgba(15, 23, 42, 0.1) !important;
  border-radius: 0.5rem !important;
  background: #ffffff !important;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12) !important;
  max-width: calc(100vw - 1rem) !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* Force override inline width styles on dropdown */
.dropdown-menu.ss-menu-panel[style*="width"],
.ss-portal-menu[style*="width"] {
  min-width: 280px !important;
  /* width: auto !important; */
}

/* Modal-hosted dropdowns should not stretch across oversized form/table cells. */
.modal .searchable-select .dropdown-menu,
.modal .tpgc-searchable-select .dropdown-menu,
.modal .dropdown-menu.ss-menu-panel,
.modal .ss-portal-menu {
  max-width: 32rem !important;
}

/* Search input - full width at top */
.searchable-select .ss-search,
.tpgc-searchable-select .ss-search,
.dropdown-menu.ss-menu-panel .ss-search,
.ss-portal-menu .ss-search {
  position: sticky !important;
  top: 0 !important;
  z-index: 2 !important;
  display: block !important;
  width: 100% !important;
  margin: 0 0 0.5rem 0 !important;
  padding: 0.6rem 0.75rem !important;
  border: 1px solid rgba(15, 23, 42, 0.1) !important;
  border-radius: 0.375rem !important;
  background: #f8fafc !important;
  box-sizing: border-box !important;
  box-shadow: none !important;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease !important;
}

.searchable-select .ss-search:focus,
.tpgc-searchable-select .ss-search:focus,
.dropdown-menu.ss-menu-panel .ss-search:focus,
.ss-portal-menu .ss-search:focus {
  border-color: #3b82f6 !important;
  outline: none !important;
  background: #ffffff !important;
}

/* List container */
.searchable-select .ss-list,
.tpgc-searchable-select .ss-list,
.dropdown-menu.ss-menu-panel .ss-list,
.ss-portal-menu .ss-list {
  margin: 0 !important;
  padding: 0 !important;
  list-style: none !important;
  display: flex !important;
  flex-direction: column !important;
}

/* List items */
.searchable-select .ss-item,
.tpgc-searchable-select .ss-item,
.dropdown-menu.ss-menu-panel .ss-item,
.ss-portal-menu .ss-item {
  display: block !important;
  padding: 0.6rem 0.75rem !important;
  border: 0 !important;
  border-bottom: 1px solid rgba(203, 213, 225, 0.5) !important;
  border-radius: 0.25rem !important;
  background: transparent !important;
  color: #1f2937 !important;
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  cursor: pointer !important;
  margin: 1px 0 !important;
}

/* Ensure d-none properly hides filtered items - higher specificity to override */
.searchable-select .ss-item.d-none,
.tpgc-searchable-select .ss-item.d-none,
.dropdown-menu.ss-menu-panel .ss-item.d-none,
.ss-portal-menu .ss-item.d-none {
  display: none !important;
  height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
}

.searchable-select .ss-item:last-child,
.tpgc-searchable-select .ss-item:last-child,
.dropdown-menu.ss-menu-panel .ss-item:last-child,
.ss-portal-menu .ss-item:last-child {
  border-bottom-color: transparent !important;
}

.searchable-select .ss-item-content,
.tpgc-searchable-select .ss-item-content,
.dropdown-menu.ss-menu-panel .ss-item-content,
.ss-portal-menu .ss-item-content {
  display: block !important;
  width: 100% !important;
}

.searchable-select .ss-item-label,
.tpgc-searchable-select .ss-item-label,
.dropdown-menu.ss-menu-panel .ss-item-label,
.ss-portal-menu .ss-item-label {
  display: block !important;
  width: 100% !important;
  font-size: 0.875rem !important;
  line-height: 1.45 !important;
  color: inherit !important;
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

/* Hover and active states */
.searchable-select .ss-item:hover,
.searchable-select .ss-item.active,
.tpgc-searchable-select .ss-item:hover,
.tpgc-searchable-select .ss-item.active,
.dropdown-menu.ss-menu-panel .ss-item:hover,
.dropdown-menu.ss-menu-panel .ss-item.active,
.ss-portal-menu .ss-item:hover,
.ss-portal-menu .ss-item.active {
  background: #f1f5f9 !important;
  color: #0f172a !important;
}

.searchable-select .ss-item.active,
.tpgc-searchable-select .ss-item.active,
.dropdown-menu.ss-menu-panel .ss-item.active,
.ss-portal-menu .ss-item.active {
  background: #e2e8f0 !important;
}

/* Group labels */
.searchable-select .ss-muted,
.tpgc-searchable-select .ss-muted,
.dropdown-menu.ss-menu-panel .ss-muted,
.ss-portal-menu .ss-muted {
  display: block !important;
  padding: 0.5rem 0.75rem !important;
  margin: 0.25rem 0 !important;
  border-bottom: 1px solid rgba(203, 213, 225, 0.5) !important;
  border-radius: 0.25rem !important;
  background: #f8fafc !important;
  color: #64748b !important;
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  letter-spacing: 0.03em !important;
}

/* Empty state */
.searchable-select .ss-empty,
.tpgc-searchable-select .ss-empty,
.dropdown-menu.ss-menu-panel .ss-empty,
.ss-portal-menu .ss-empty {
  padding: 1rem !important;
  color: #64748b !important;
  text-align: center !important;
}

/* Focus backdrop - subtle overlay */
.ss-focus-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.03);
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-in-out;
  z-index: 1990;
}

.ss-focus-backdrop.show {
  opacity: 1;
}

[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel,
[data-bs-theme="dark"] .ss-portal-menu {
  border-color: var(--bs-border-color) !important;
  background: var(--bs-body-bg) !important;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45) !important;
}

[data-bs-theme="dark"] .searchable-select .ss-search,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-search,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-search,
[data-bs-theme="dark"] .ss-portal-menu .ss-search {
  border-color: var(--bs-border-color) !important;
  background: color-mix(in srgb, var(--bs-body-bg) 78%, var(--bs-tertiary-bg)) !important;
  color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .searchable-select .ss-search:focus,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-search:focus,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-search:focus,
[data-bs-theme="dark"] .ss-portal-menu .ss-search:focus {
  border-color: var(--bs-primary) !important;
  background: var(--bs-body-bg) !important;
}

[data-bs-theme="dark"] .searchable-select .ss-item,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-item,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-item,
[data-bs-theme="dark"] .ss-portal-menu .ss-item {
  border-bottom-color: color-mix(in srgb, var(--bs-border-color) 68%, transparent) !important;
  color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .searchable-select .ss-item:hover,
[data-bs-theme="dark"] .searchable-select .ss-item.active,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-item:hover,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-item.active,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-item:hover,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-item.active,
[data-bs-theme="dark"] .ss-portal-menu .ss-item:hover,
[data-bs-theme="dark"] .ss-portal-menu .ss-item.active {
  background: color-mix(in srgb, var(--bs-primary) 18%, transparent) !important;
  color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .searchable-select .ss-muted,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-muted,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-muted,
[data-bs-theme="dark"] .ss-portal-menu .ss-muted {
  border-bottom-color: color-mix(in srgb, var(--bs-border-color) 68%, transparent) !important;
  background: color-mix(in srgb, var(--bs-secondary-bg) 74%, var(--bs-body-bg)) !important;
  color: var(--bs-secondary-color) !important;
}

[data-bs-theme="dark"] .searchable-select .ss-empty,
[data-bs-theme="dark"] .tpgc-searchable-select .ss-empty,
[data-bs-theme="dark"] .dropdown-menu.ss-menu-panel .ss-empty,
[data-bs-theme="dark"] .ss-portal-menu .ss-empty {
  color: var(--bs-secondary-color) !important;
}

/* Scroll lock for body */
html.ss-scroll-locked,
body.ss-scroll-locked {
  overflow: hidden !important;
  overscroll-behavior: none !important;
  touch-action: none !important;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .searchable-select,
  .tpgc-searchable-select {
    width: 100% !important;
    display: block !important;
  }

  .searchable-select .dropdown-menu,
  .tpgc-searchable-select .dropdown-menu {
    width: 100% !important;
  }

  .searchable-select .btn.form-select,
  .tpgc-searchable-select .btn.form-select {
    width: 100% !important;
    min-width: 100% !important;
  }

  .dropdown-menu.ss-menu-panel,
  .ss-portal-menu {
    max-height: 62vh !important;
    border-radius: 0.5rem !important;
    padding: 0.5rem !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12) !important;
  }

  .ss-portal-menu.ss-mobile-anchored {
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: auto !important;
    max-width: calc(100vw - 16px) !important;
    border: 1px solid rgba(15, 23, 42, 0.1) !important;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12) !important;
  }

  .searchable-select .ss-item,
  .tpgc-searchable-select .ss-item,
  .dropdown-menu.ss-menu-panel .ss-item,
  .ss-portal-menu .ss-item {
    padding: 0.65rem 0.75rem !important;
    font-size: 0.9rem !important;
  }

  .searchable-select .btn.form-select .ss-label,
  .tpgc-searchable-select .btn.form-select .ss-label {
    display: block !important;
    color: #1f2937 !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
}

/* ============================================================================
   SEARCHABLE SELECT DROPDOWN
   ============================================================================ */

.searchable-select,
.tpgc-searchable-select {
  position: relative;
  width: 100%;
  --ss-border: rgba(15, 23, 42, 0.12);
  --ss-border-strong: rgba(46, 49, 146, 0.24);
  --ss-divider: rgba(203, 213, 225, 0.95);
  --ss-surface: #ffffff;
  --ss-surface-subtle: #f7fafc;
  --ss-text: #1f2937;
  --ss-text-muted: #607080;
  --ss-hover: #f3f7fb;
  --ss-active: #eef4ff;
  --ss-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
  --ss-radius: 0;
}

.searchable-select .dropdown-menu,
.tpgc-searchable-select .dropdown-menu,
.ss-portal-menu {
  width: 100%;
  max-height: 320px;
  overflow-y: auto;
  box-sizing: border-box;
  z-index: 9999;
  margin-top: 0.25rem !important;
  padding: 0.35rem !important;
  border: 1px solid var(--ss-border) !important;
  border-radius: 0 !important;
  background: var(--ss-surface) !important;
  box-shadow: var(--ss-shadow) !important;
}

.searchable-select .btn.form-select,
.tpgc-searchable-select .btn.form-select {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: space-between !important;
  gap: 0.5rem !important;
  width: 100% !important;
  height: auto !important;
  min-height: 42px !important;
  min-width: 150px !important;
  padding: 0.625rem 0.875rem !important;
  font-size: 0.92rem !important;
  font-weight: 500 !important;
  line-height: 1.4 !important;
  color: var(--ss-text) !important;
  background-color: var(--ss-surface) !important;
  background-image: none !important;
  border: 1px solid var(--ss-border) !important;
  border-radius: 0 !important;
  cursor: pointer !important;
  text-align: left !important;
  box-shadow: none !important;
  transition:
    border-color 0.12s linear,
    box-shadow 0.12s linear,
    background-color 0.12s linear !important;
}

.searchable-select .btn.form-select:hover,
.tpgc-searchable-select .btn.form-select:hover {
  border-color: var(--ss-border-strong) !important;
  background: var(--ss-surface-subtle) !important;
}

.searchable-select .btn.form-select:focus,
.searchable-select .btn.form-select.show,
.tpgc-searchable-select .btn.form-select:focus,
.tpgc-searchable-select .btn.form-select.show {
  border-color: #2e3192 !important;
  outline: 0 !important;
  box-shadow: 0 0 0 1px rgba(46, 49, 146, 0.14) !important;
}

.searchable-select .btn.form-select .ss-label,
.tpgc-searchable-select .btn.form-select .ss-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: inherit;
}

.searchable-select .ss-trigger,
.tpgc-searchable-select .ss-trigger {
  border-radius: 0 !important;
}

.searchable-select .bi-caret-down-fill,
.tpgc-searchable-select .bi-caret-down-fill {
  margin-left: 0.25rem !important;
  margin-top: 0.2rem !important;
  flex: 0 0 auto;
  font-size: 0.72rem !important;
  color: #7b8794 !important;
}

.searchable-select .ss-search,
.tpgc-searchable-select .ss-search,
.ss-portal-menu .ss-search {
  position: sticky !important;
  top: 0 !important;
  z-index: 2 !important;
  margin-bottom: 0.45rem !important;
  padding: 0.55rem 0.75rem !important;
  border: 1px solid var(--ss-border) !important;
  border-radius: 0 !important;
  background: var(--ss-surface) !important;
  box-shadow: none !important;
}

.searchable-select .ss-list,
.tpgc-searchable-select .ss-list,
.ss-portal-menu .ss-list {
  list-style: none !important;
  padding-left: 0 !important;
  margin: 0 !important;
}

.searchable-select .ss-list,
.searchable-select .ss-list li,
.searchable-select .ss-item,
.searchable-select .ss-muted,
.tpgc-searchable-select .ss-list,
.tpgc-searchable-select .ss-list li,
.tpgc-searchable-select .ss-item,
.tpgc-searchable-select .ss-muted,
.ss-portal-menu .ss-list,
.ss-portal-menu .ss-list li,
.ss-portal-menu .ss-item,
.ss-portal-menu .ss-muted {
  list-style: none !important;
}

.searchable-select .ss-list li::marker,
.searchable-select .ss-item::marker,
.searchable-select .ss-muted::marker,
.tpgc-searchable-select .ss-list li::marker,
.tpgc-searchable-select .ss-item::marker,
.tpgc-searchable-select .ss-muted::marker,
.ss-portal-menu .ss-list li::marker,
.ss-portal-menu .ss-item::marker,
.ss-portal-menu .ss-muted::marker {
  content: '' !important;
}

.searchable-select .ss-item,
.tpgc-searchable-select .ss-item,
.ss-portal-menu .ss-item {
  display: block;
  padding: 0.8rem 0.9rem !important;
  font-size: 0.875rem !important;
  line-height: 1.4 !important;
  color: var(--ss-text) !important;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  cursor: pointer !important;
  border: 0 !important;
  border-bottom: 1px solid var(--ss-divider) !important;
  border-radius: 0 !important;
  transition:
    background-color 0.08s linear,
    border-color 0.08s linear,
    color 0.08s linear !important;
}

.searchable-select .ss-item:last-child,
.tpgc-searchable-select .ss-item:last-child,
.ss-portal-menu .ss-item:last-child {
  border-bottom-color: transparent;
}

.searchable-select .ss-item:hover,
.searchable-select .ss-item.active,
.tpgc-searchable-select .ss-item:hover,
.tpgc-searchable-select .ss-item.active,
.ss-portal-menu .ss-item:hover,
.ss-portal-menu .ss-item.active {
  background-color: var(--ss-hover) !important;
  color: #18212b !important;
}

.searchable-select .ss-item.active,
.tpgc-searchable-select .ss-item.active,
.ss-portal-menu .ss-item.active {
  background-color: var(--ss-active) !important;
  box-shadow: inset 2px 0 0 #2e3192;
}

.searchable-select .ss-muted,
.tpgc-searchable-select .ss-muted,
.ss-portal-menu .ss-muted {
  color: var(--ss-text-muted) !important;
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  letter-spacing: 0.03em;
  padding: 0.6rem 0.9rem !important;
  margin-bottom: 0.35rem !important;
  background: var(--ss-surface-subtle) !important;
  border-bottom: 1px solid var(--ss-divider) !important;
  border-radius: 0 !important;
}

/* ============================================================================
   MOBILE SEARCHABLE SELECT
   ============================================================================ */

@media (max-width: 768px) {
  .searchable-select .btn.form-select,
  .tpgc-searchable-select .btn.form-select {
    font-size: 0.98rem !important;
    min-height: 44px !important;
    padding: 0.7rem 0.85rem !important;
  }

  .searchable-select .dropdown-menu,
  .tpgc-searchable-select .dropdown-menu,
  .ss-portal-menu {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-height: 62vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    padding: 0.75rem !important;
  }

  .searchable-select .ss-item,
  .tpgc-searchable-select .ss-item,
  .ss-portal-menu .ss-item {
    padding: 0.8rem 0.9rem !important;
    font-size: 0.95rem !important;
  }

  .searchable-select .ss-search,
  .tpgc-searchable-select .ss-search,
  .ss-portal-menu .ss-search {
    position: sticky !important;
    top: 0 !important;
    padding: 0.7rem 0.8rem !important;
  }
}
