/* ===== CUSTOM SELECT ===== */
.custom-select {
  position: relative;
  display: inline-block;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  flex-shrink: 0;
  box-sizing: border-box;
  min-width: 0;
}

/* Cuando está en un contexto flex, permitir que el ancho sea controlado por el contenedor */
.products-adm__actions .custom-select {
  width: auto !important; /* Ancho automático como los otros botones */
  min-width: 140px; /* Default */
  max-width: 280px;
}

/* Herramientas: trigger más angosto (como un botón), pero el dropdown se ensancha por JS */
.products-adm__actions .custom-select.custom-select--tools {
  min-width: 120px !important;
  max-width: 200px !important;
}

/* Trigger (botón principal) */
.custom-select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 28px 8px 12px; /* Padding derecho para la flecha */
  background: var(--card);
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  color: var(--fg);
  font-size: 0.95rem;
  font-weight: 400;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  height: 36px;
  box-sizing: border-box;
  line-height: normal;
  position: relative;
  width: 100%;
  min-width: 0;
}

/* CustomSelect de herramientas - que se vea igual que los botones y filtros */
.custom-select--tools .custom-select__trigger {
  height: 28px !important;                  /* mismo alto que los botones y selects de filtros */
  padding: 4px 28px 4px 12px !important;    /* mismo padding que los botones (4px arriba/abajo) */
  font-size: 0.9rem !important;             /* mismo tamaño que los botones */
  font-weight: 600 !important;              /* mismo peso que los botones (semibold) */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important; /* misma fuente del sistema */
  line-height: normal !important;           /* mismo line-height que los botones */
  border: 2px solid var(--border-strong) !important; /* mismo borde que los botones */
  border-radius: 10px !important;
  background: var(--card) !important;
  box-sizing: border-box !important;        /* asegurar que el borde esté incluido en la altura */
  transition: border-color 0.15s, box-shadow 0.15s !important;
  color: var(--fg) !important;               /* mismo color que los botones */
  width: auto !important;                   /* ancho automático basado en contenido */
  min-width: 120px !important;              /* más angosto que el default */
  letter-spacing: normal !important;        /* sin espaciado extra */
  text-transform: none !important;          /* sin transformación de texto */
  -webkit-font-smoothing: antialiased !important; /* mismo renderizado que los botones */
  -moz-osx-font-smoothing: grayscale !important;
  text-rendering: optimizeLegibility !important;
}

.custom-select__trigger:hover {
  border-color: color-mix(in srgb, var(--fg) 28%, var(--border));
}

.custom-select__trigger:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(255,122,0,.15);
}

.custom-select--open .custom-select__trigger {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(255,122,0,.15);
}

/* Valor seleccionado */
.custom-select__value {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}

/* Placeholder en negrita */
.custom-select__value strong {
  font-weight: 700;
}

/* Para CustomSelect de herramientas, el valor siempre igual que los botones */
/* IMPORTANTE: Sobrescribir el font-weight: 400 del .custom-select__value base */
.custom-select--tools .custom-select__trigger .custom-select__value,
.custom-select--tools .custom-select__value {
  font-weight: 600 !important;
  font-size: 0.9rem !important; /* Igualar tamaño de fuente con los botones - FORZADO */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  line-height: normal !important; /* mismo line-height que los botones */
  color: var(--fg) !important; /* mismo color que los botones */
  letter-spacing: normal !important; /* sin espaciado extra */
  text-transform: none !important; /* sin transformación de texto */
  -webkit-font-smoothing: antialiased !important; /* mismo renderizado que los botones */
  -moz-osx-font-smoothing: grayscale !important;
  text-rendering: optimizeLegibility !important;
  /* Forzar con shorthand font para máxima prioridad */
  font: 600 0.9rem/normal -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

/* Si el value tiene un span o elemento interno, también forzar el mismo tamaño */
.custom-select--tools .custom-select__value *,
.custom-select--tools .custom-select__trigger .custom-select__value * {
  font-size: 0.9rem !important;
  font-weight: 600 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  font: 600 0.9rem/normal -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

.custom-select--tools .custom-select__value strong {
  font-weight: 700 !important;
}

/* Flecha */
.custom-select__arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  flex-shrink: 0;
  font-size: 0.7rem;
  transition: transform 0.2s;
  opacity: 0.7;
  pointer-events: none;
}

.custom-select--open .custom-select__arrow {
  transform: translateY(-50%) rotate(180deg);
}

/* Dropdown */
.custom-select__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--card);
  border: 2px solid var(--brand-500);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 99999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}

.custom-select.custom-select--portaled .custom-select__dropdown {
  position: fixed !important;
}

.custom-select__dropdown[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* Buscador */
.custom-select__search {
  padding: 6px;
  border-bottom: 1px solid var(--border);
}

.custom-select__search-input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.85rem;
  height: 30px;
  box-sizing: border-box;
}

.custom-select__search-input:focus {
  outline: none;
  border-color: var(--brand-500);
}

/* Contenedor de opciones */
.custom-select__options {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 3px 0;
}

/* Scrollbar personalizado */
.custom-select__options::-webkit-scrollbar {
  width: 8px;
}

.custom-select__options::-webkit-scrollbar-track {
  background: var(--gray-100);
  border-radius: 4px;
}

.custom-select__options::-webkit-scrollbar-thumb {
  background: var(--gray-400);
  border-radius: 4px;
}

.custom-select__options::-webkit-scrollbar-thumb:hover {
  background: var(--gray-500);
}

/* Opción */
.custom-select__option {
  padding: 0 12px;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 0.15s;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  min-height: calc(0.95rem * 1.4);
  white-space: nowrap;
}

/* Opción de pageSize con checkbox */
.custom-select__option--pagesize {
  padding: 0 12px;
  line-height: 1.4;
  font-size: 0.95rem;
  min-height: calc(0.95rem * 1.4);
}

.custom-select__option-text {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.custom-select__option-name {
  flex: 1;
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

/* En el dropdown abierto, mostrar texto completo (sin recorte) */
.custom-select__dropdown[aria-hidden="false"] .custom-select__option-name {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
  word-break: normal;
}

.custom-select__option-count {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  margin-left: auto;
  padding-left: 8px;
}

.custom-select__option:hover {
  background-color: var(--gray-100);
}

.custom-select__option--selected {
  background-color: var(--brand-50);
  color: var(--brand-600);
  font-weight: 600;
}

.custom-select__option--selected:hover {
  background-color: color-mix(in srgb, var(--brand-50) 80%, var(--brand-100) 20%);
}

/* Borde inferior para opciones */
.custom-select__option--bordered {
  border-bottom: 1.5px solid var(--gray-300);
}

.custom-select__option--bordered:last-child {
  border-bottom: none;
}

/* Checkbox visual para opciones de pageSize */
.custom-select__checkbox {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid var(--gray-400);
  border-radius: 4px;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  cursor: pointer;
  position: relative;
}

.custom-select__checkbox-inner {
  width: 10px;
  height: 10px;
  background: var(--brand-500);
  border-radius: 2px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.15s;
}

.custom-select__checkbox--checked {
  border-color: var(--brand-500);
  background: var(--brand-50);
}

.custom-select__checkbox--checked .custom-select__checkbox-inner {
  opacity: 1;
  transform: scale(1);
}

.custom-select__option--pagesize:hover .custom-select__checkbox,
.custom-select__dropdown--multiple .custom-select__option:hover .custom-select__checkbox {
  border-color: var(--brand-500);
}

.custom-select__option--pagesize.custom-select__option--selected .custom-select__checkbox,
.custom-select__dropdown--multiple .custom-select__option--selected .custom-select__checkbox {
  border-color: var(--brand-500);
  background: var(--brand-50);
}

/* Estilos específicos para modo múltiple */
.custom-select__dropdown--multiple .custom-select__option {
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.4;
  font-size: 0.95rem;
  min-height: calc(0.95rem * 1.4);
}

/* Opciones deshabilitadas (separadores) */
.custom-select__option--disabled {
  pointer-events: none;
  cursor: default;
  color: var(--gray-400);
  background-color: transparent !important;
  text-align: center;
  padding: 4px 12px;
  font-size: 0.7rem;
  user-select: none;
  letter-spacing: -1px;
  display: block;
}

.dark .custom-select__option--disabled,
[data-theme="dark"] .custom-select__option--disabled {
  color: var(--gray-500);
}

@media (prefers-color-scheme: dark) {
  :root:not(.force-light) .custom-select__option--disabled {
    color: var(--gray-500);
  }
}

/* Estado disabled */
.custom-select.custom-select--disabled .custom-select__trigger {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--gray-100);
}

/* Modo oscuro */
.dark .custom-select__trigger,
[data-theme="dark"] .custom-select__trigger {
  border: 2px solid var(--border-strong);
  color: var(--fg) !important;
  background: var(--card) !important;
}

.dark .custom-select__value,
[data-theme="dark"] .custom-select__value {
  color: var(--fg) !important;
}

.dark .custom-select__trigger:hover,
[data-theme="dark"] .custom-select__trigger:hover {
  border-color: color-mix(in srgb, var(--fg) 28%, var(--border));
}

.dark .custom-select__trigger:focus,
[data-theme="dark"] .custom-select__trigger:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(255,122,0,.40);
}

.dark .custom-select--open .custom-select__trigger,
[data-theme="dark"] .custom-select--open .custom-select__trigger {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(255,122,0,.40);
}

.dark .custom-select__dropdown,
[data-theme="dark"] .custom-select__dropdown {
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  border-color: var(--brand-400);
}

.dark .custom-select__option,
[data-theme="dark"] .custom-select__option {
  color: #ffffff !important;
}

.dark .custom-select__option-text,
[data-theme="dark"] .custom-select__option-text {
  color: #ffffff !important;
}

.dark .custom-select__option:hover,
[data-theme="dark"] .custom-select__option:hover {
  background-color: var(--gray-200);
  color: #ffffff !important;
}

.dark .custom-select__option:hover .custom-select__option-text,
[data-theme="dark"] .custom-select__option:hover .custom-select__option-text {
  color: #ffffff !important;
}

.dark .custom-select__option--selected,
[data-theme="dark"] .custom-select__option--selected {
  background-color: var(--brand-50);
  color: var(--brand-400);
}

.dark .custom-select__option--selected .custom-select__option-text,
[data-theme="dark"] .custom-select__option--selected .custom-select__option-text {
  color: var(--brand-400) !important;
}

.dark .custom-select__option--selected:hover,
[data-theme="dark"] .custom-select__option--selected:hover {
  background-color: color-mix(in srgb, var(--brand-50) 80%, var(--brand-100) 20%);
  color: var(--brand-400) !important;
}

.dark .custom-select__option--selected:hover .custom-select__option-text,
[data-theme="dark"] .custom-select__option--selected:hover .custom-select__option-text {
  color: var(--brand-400) !important;
}

.dark .custom-select__option--bordered,
[data-theme="dark"] .custom-select__option--bordered {
  border-bottom: 1.5px solid var(--gray-400) !important;
}

.dark .custom-select__checkbox,
[data-theme="dark"] .custom-select__checkbox {
  border-color: var(--gray-500);
  background: var(--gray-200);
}

.dark .custom-select__checkbox--checked,
[data-theme="dark"] .custom-select__checkbox--checked {
  border-color: var(--brand-400);
  background: var(--brand-50);
}

.dark .custom-select__option--pagesize:hover .custom-select__checkbox,
[data-theme="dark"] .custom-select__option--pagesize:hover .custom-select__checkbox {
  border-color: var(--brand-400);
}

@media (prefers-color-scheme: dark) {
  :root:not(.force-light) .custom-select__trigger {
    border: 2px solid var(--border-strong);
    color: var(--fg) !important;
    background: var(--card) !important;
  }
  
  :root:not(.force-light) .custom-select__value {
    color: var(--fg) !important;
  }
  
  :root:not(.force-light) .custom-select__trigger:hover {
    border-color: color-mix(in srgb, var(--fg) 28%, var(--border));
  }
  
  :root:not(.force-light) .custom-select__trigger:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(255,122,0,.40);
  }
  
  :root:not(.force-light) .custom-select--open .custom-select__trigger {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(255,122,0,.40);
  }
  
  :root:not(.force-light) .custom-select__dropdown {
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
    border-color: var(--brand-400);
  }
  
  :root:not(.force-light) .custom-select__option {
    color: #ffffff !important;
  }
  
  :root:not(.force-light) .custom-select__option-text {
    color: #ffffff !important;
  }
  
  :root:not(.force-light) .custom-select__option:hover {
    background-color: var(--gray-200);
    color: #ffffff !important;
  }
  
  :root:not(.force-light) .custom-select__option:hover .custom-select__option-text {
    color: #ffffff !important;
  }
  
  :root:not(.force-light) .custom-select__option--selected {
    background-color: var(--brand-50);
    color: var(--brand-400);
  }
  
  :root:not(.force-light) .custom-select__option--selected .custom-select__option-text {
    color: var(--brand-400) !important;
  }
  
  :root:not(.force-light) .custom-select__option--selected:hover {
    background-color: color-mix(in srgb, var(--brand-50) 80%, var(--brand-100) 20%);
    color: var(--brand-400) !important;
  }
  
  :root:not(.force-light) .custom-select__option--selected:hover .custom-select__option-text {
    color: var(--brand-400) !important;
  }
  
  :root:not(.force-light) .custom-select__option--bordered {
    border-bottom: 1.5px solid var(--gray-400) !important;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .custom-select__trigger {
    font-size: 0.9rem;
  }
  
  .custom-select__option {
    padding: 4px 10px;
    font-size: 0.9rem;
  }
}

@media (max-width: 600px) {
  .custom-select__trigger {
    font-size: 0.85rem;
    padding: 7px 10px;
  }
  
  .custom-select__option {
    padding: 4px 10px;
    font-size: 0.85rem;
  }
}
