/**
 * Multiselect Component Styles
 *
 * Struktur wie Searchable Select:
 * - Display: Tags + Placeholder + Pfeil (Underline Style)
 * - Dropdown: Suchfeld + Optionen
 */

/* ========================================
   Container
   ======================================== */
.multiselect {
  position: relative;
  width: 100%;
}

.multiselect[data-disabled="true"] {
  pointer-events: none;
}

/* Placeholder ausgegraut wenn disabled und leer */
.multiselect[data-disabled="true"] .multiselect-placeholder {
  opacity: 0.6;
}

/* ========================================
   Display (Underline Style) - wie Searchable Select
   ======================================== */
.multiselect-display {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 10px 0;
  border: none;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  border-radius: 0;
  background-color: transparent;
  cursor: pointer;
  transition: border-color 0.2s, border-width 0.2s;
  margin-bottom: 0;
}

.multiselect-display:hover {
  border-bottom-color: var(--grey-400, #9ca3af);
}

.multiselect-display:focus {
  outline: none;
  border-bottom-width: 2px;
  border-bottom-color: var(--primary-color, #007abb);
  margin-bottom: -0.75px;
}

.multiselect.open .multiselect-display {
  border-bottom-width: 2px;
  border-bottom-color: var(--primary-color, #007abb);
  margin-bottom: -0.75px;
}

/* Tags Container */
.multiselect-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
  align-items: center;
}

/* Individual Tag - wie Tabellen-Chips */
.multiselect-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background-color: var(--primary-light);
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  max-width: 220px;
  white-space: nowrap;
}

.multiselect-tag .tag-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Runder Schließen-Button */
.multiselect-tag .tag-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  background-color: var(--primary-bg);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.15s;
  flex-shrink: 0;
}

.multiselect-tag .tag-remove:hover {
  background-color: var(--primary-color, #007abb);
  color: white;
}

.multiselect-tag .tag-remove svg {
  pointer-events: none;
  width: 10px;
  height: 10px;
}

/* Placeholder */
.multiselect-placeholder {
  color: var(--text-muted, #6b7280);
  font-size: 14px;
}

/* Arrow Icon */
.multiselect-arrow {
  flex-shrink: 0;
  margin-left: 8px;
  color: var(--text-muted, #6b7280);
  transition: transform 0.2s;
}

.multiselect.open .multiselect-arrow {
  transform: rotate(180deg);
}

/* ========================================
   Dropdown Container
   ======================================== */
.multiselect-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background-color: var(--surface, #ffffff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 99999;
  max-height: 300px;
  flex-direction: column;
}

.multiselect.open .multiselect-dropdown,
.multiselect-dropdown.portal-open {
  display: flex;
  animation: msDropdownAppear 0.15s ease-out;
}

/* Multiselect in Modal - z-index fix */
.modal .multiselect-dropdown,
.modal-overlay .multiselect-dropdown {
  z-index: 100001;
}

@keyframes msDropdownAppear {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dropdown opens upward */
.multiselect.dropdown-up .multiselect-arrow {
  transform: rotate(180deg);
}

.multiselect.dropdown-up.open .multiselect-arrow {
  transform: rotate(0deg);
}

/* ========================================
   Search Input (im Dropdown)
   ======================================== */
.multiselect-search {
  padding: 8px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.multiselect-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-primary, #1e293b);
  background-color: var(--surface, #ffffff);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.multiselect-search-input:focus {
  outline: none;
  border-color: var(--primary-color, #007abb);
  box-shadow: 0 0 0 3px rgba(0, 122, 187, 0.1);
}

.multiselect-search-input::placeholder {
  color: var(--text-muted, #6b7280);
}

/* ========================================
   Options Container
   ======================================== */
.multiselect-options {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ========================================
   Option Items
   ======================================== */
.multiselect-option,
.multiselect-select-all {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary, #1e293b);
  transition: background-color 0.1s;
}

.multiselect-option:hover,
.multiselect-option.highlighted,
.multiselect-select-all:hover,
.multiselect-select-all.highlighted {
  background-color: var(--grey-100, #f3f4f6);
}

.multiselect-option.selected,
.multiselect-select-all.selected {
  background-color: var(--primary-light);
  color: var(--text-primary);
}

.multiselect-option.selected:hover,
.multiselect-option.selected.highlighted,
.multiselect-select-all.selected:hover,
.multiselect-select-all.selected.highlighted {
  background-color: var(--primary-lighter, #bae6fd);
}

/* Option Text */
.multiselect-option .option-text,
.multiselect-select-all .option-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Check Icon - rechts positioniert (wie SearchableSelect) */
.multiselect-option .check-icon,
.multiselect-select-all .check-icon {
  flex-shrink: 0;
  margin-left: auto;
  width: 16px;
  height: 16px;
  opacity: 0;
  color: var(--primary-color, #007abb);
  transition: opacity 0.1s;
}

.multiselect-option.selected .check-icon,
.multiselect-select-all.selected .check-icon {
  opacity: 1;
}

/* Select All - Separator */
.multiselect-select-all {
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  font-weight: 500;
}

/* ========================================
   Group Headers (Optgroup-Style)
   ======================================== */
.multiselect-group-header {
  padding: 8px 12px 6px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted, #6b7280);
  background-color: var(--grey-50, #f9fafb);
  border-top: 1px solid var(--border-color, #e5e7eb);
  cursor: default;
  user-select: none;
}

.multiselect-group-header:first-child,
.multiselect-select-all + .multiselect-group-header {
  border-top: none;
}

/* ========================================
   No Results Message
   ======================================== */
.multiselect-no-results {
  padding: 12px;
  text-align: center;
  color: var(--text-muted, #6b7280);
  font-size: 14px;
  font-style: italic;
}

/* ========================================
   Empty State (keine Optionen vorhanden)
   ======================================== */
.multiselect-empty {
  padding: 16px 12px;
  text-align: center;
  color: var(--text-muted, #6b7280);
  font-size: 14px;
}

.multiselect-empty-icon {
  margin-bottom: 8px;
  opacity: 0.5;
}

/* Suchfeld ausblenden wenn keine Optionen */
.multiselect.empty .multiselect-search {
  display: none;
}

/* ========================================
   Disabled State
   ======================================== */
.multiselect[data-disabled="true"] .multiselect-display {
  cursor: not-allowed;
}

.multiselect[data-disabled="true"] .multiselect-tag {
  background-color: var(--grey-200, #e5e7eb);
  color: var(--text-muted, #6b7280);
}

.multiselect[data-disabled="true"] .multiselect-tag .tag-remove {
  display: none;
}

/* ========================================
   Filter Field Integration
   ======================================== */
.filter-field .multiselect-display {
  min-height: 36px;
  padding: 4px 0;
}

.filter-field .multiselect-tag {
  font-size: 11px;
  padding: 2px 6px 2px 8px;
}

.filter-field .multiselect-placeholder {
  font-size: 13px;
}

/* ========================================
   Form Group Integration
   ======================================== */
.form-group .multiselect-display {
  min-height: 40px;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 640px) {
  .multiselect-options {
    max-height: 200px;
  }

  .multiselect-tag {
    max-width: 120px;
  }
}

/* ========================================
   Filtered Options (JS-controlled visibility)
   ======================================== */
.multiselect-option.tom-filtered,
.multiselect-option.standard-filtered {
  display: none !important;
}
