/* =========================================================================
   NIGHTDESK CUSTOM SELECT COMPONENT STYLES
   ========================================================================= */

/* Visually hide original native select once enhanced on desktop */
.nd-select-hidden {
  position: absolute !important;
  opacity: 0 !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  pointer-events: none !important;
}

/* Hide native wrapper select icons when custom select is present */
.nd-sub-select-wrap .nd-select + .nd-sub-select-icon,
.nd-contact-select-wrap .nd-select + .nd-contact-select-icon {
  display: none !important;
}

/* Custom Select Root Container */
.nd-select {
  position: relative;
  width: 100%;
  box-sizing: border-box;
}

/* Trigger Button */
.nd-select-trigger {
  width: 100%;
  height: 50px;
  padding: 0 44px 0 15px;
  font-size: 16px;
  text-align: left;
  background: var(--nd-bg-raised);
  border: 1px solid var(--nd-border);
  border-radius: 6px;
  color: var(--nd-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-sizing: border-box;
  outline: none;
  transition: border-color 160ms ease, background-color 160ms ease;
  user-select: none;
}

.nd-select-trigger:hover {
  border-color: var(--nd-muted);
}

.nd-select-trigger:focus-visible {
  border-color: var(--nd-accent);
}

.nd-select.is-open .nd-select-trigger {
  border-color: var(--nd-accent);
}

.nd-select-trigger.is-placeholder .nd-select-value {
  color: var(--nd-muted);
}

/* Trigger Value & Chevron Icon */
.nd-select-value {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.nd-select-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--nd-muted);
  width: 17px;
  height: 17px;
}

.nd-select-icon svg {
  width: 17px;
  height: 17px;
  transition: transform 200ms ease;
}

.nd-select.is-open .nd-select-icon svg {
  transform: rotate(180deg);
}

/* Dropdown Panel */
.nd-select-panel {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  margin-top: 6px;
  background: var(--nd-bg-raised);
  border: 1px solid var(--nd-border);
  border-radius: 10px;
  overflow: hidden;
  z-index: 200;
  max-height: 320px;
  padding: 6px 0;
  box-shadow: 0 14px 36px var(--nd-shadow);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.nd-select.is-open .nd-select-panel {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Dropup Position (when opening upward) */
.nd-select--dropup .nd-select-panel {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 6px;
  transform: translateY(6px);
}

.nd-select--dropup.is-open .nd-select-panel {
  transform: translateY(0);
}

/* Search Box inside Panel */
.nd-select-search {
  padding: 6px 10px 10px;
  border-bottom: 1px solid var(--nd-border);
  margin-bottom: 4px;
  background: var(--nd-bg-raised);
  flex-shrink: 0;
}

.nd-select-search[hidden] {
  display: none !important;
}

.nd-select-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  background: var(--nd-bg);
  border: 1px solid var(--nd-border);
  border-radius: 6px;
  color: var(--nd-text);
  outline: none;
  box-sizing: border-box;
  transition: border-color 140ms ease;
}

.nd-select-search input:focus {
  border-color: var(--nd-accent);
}

.nd-select-search input::placeholder {
  color: var(--nd-muted);
  opacity: 0.8;
}

/* Options List */
.nd-select-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: 280px;
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.nd-select-list::-webkit-scrollbar {
  display: none;
}

/* Option Items */
.nd-select-option {
  padding: 11px 15px;
  margin: 2px 6px;
  font-size: 16px;
  line-height: 1.4;
  color: var(--nd-muted);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 140ms ease, color 140ms ease;
  user-select: none;
  box-sizing: border-box;
  outline: none;
}

.nd-select-option:hover,
.nd-select-option.is-focused {
  background: var(--nd-bg);
  color: var(--nd-accent);
}

.nd-select-option.is-selected {
  color: var(--nd-accent);
  font-weight: 500;
}

.nd-select-option[hidden],
.nd-select-option.is-hidden {
  display: none !important;
}

.nd-select-option-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tick Icon for Selected Option */
.nd-select-tick {
  display: none;
  width: 16px;
  height: 16px;
  stroke: var(--nd-accent);
  margin-left: 10px;
  flex-shrink: 0;
}

.nd-select-option.is-selected .nd-select-tick {
  display: inline-block;
}

/* Hierarchical Child Option */
.nd-select-option--child {
  padding-left: 30px;
  font-size: 14px;
  border-left: 1px solid var(--nd-border);
  margin-left: 10px;
  margin-right: 6px;
  border-radius: 0 6px 6px 0;
}

.nd-select-option--child:hover,
.nd-select-option--child.is-focused {
  border-left-color: var(--nd-accent);
}

/* Empty State */
.nd-select-empty {
  padding: 16px 15px;
  font-size: 14px;
  color: var(--nd-muted);
  text-align: center;
  margin: 0;
}

.nd-select-empty[hidden] {
  display: none !important;
}

/* Error States in Forms */
.nd-sub-field--error .nd-select-trigger,
.nd-contact-field--error .nd-select-trigger,
.nd-auth-field--error .nd-select-trigger,
.nd-field--error .nd-select-trigger,
.has-error .nd-select-trigger,
.nd-select--error .nd-select-trigger {
  border-color: var(--nd-danger-strong) !important;
}

/* Mobile: below 640px native select remains active */
@media (max-width: 640px) {
  .nd-select {
    display: none !important;
  }
  .nd-select-hidden {
    position: static !important;
    opacity: 1 !important;
    width: 100% !important;
    height: 50px !important;
    margin: 0 !important;
    padding: 0 15px !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
    pointer-events: auto !important;
  }
  .nd-sub-select-wrap .nd-select + .nd-sub-select-icon,
  .nd-contact-select-wrap .nd-select + .nd-contact-select-icon {
    display: flex !important;
  }
}
