/* Tom Select custom styles for ActiveAdmin integration */

.ts-control {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  min-height: 38px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.5;
  color: #374151;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.ts-control.single .ts-control {
  padding: 8px 32px 8px 12px;
  height: 38px;
}

.ts-control.multi .ts-control {
  padding: 4px 8px;
}

/* Focus state */
.ts-control.focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
  outline: none;
}

/* Disabled state */
.ts-control.disabled {
  background-color: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}

.ts-control.disabled input {
  background-color: transparent;
}

/* Input styling */
.ts-control input {
  color: inherit;
  font-size: inherit;
  font-family: inherit;
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
}

.ts-control input::placeholder {
  color: #9ca3af;
}

/* Single select arrow */
.ts-control.single:not(.input-active)::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #6b7280;
}

.ts-control.single.dropdown-active:not(.input-active)::after {
  border-top: none;
  border-bottom: 5px solid #6b7280;
}

/* Items (selected options) */
.ts-control .item {
  background: #e5e7eb;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  color: #374151;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ts-control .item.active {
  background: #3b82f6;
  color: white;
  border-color: #2563eb;
}

/* Remove button for items */
.ts-control .item .remove {
  color: #6b7280;
  cursor: pointer;
  font-weight: bold;
  margin-left: 4px;
  padding: 0 2px;
  border-radius: 2px;
  font-size: 12px;
}

.ts-control .item .remove:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Dropdown */
.ts-dropdown {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
}

.ts-dropdown .option {
  padding: 8px 12px;
  color: #374151;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
}

.ts-dropdown .option:last-child {
  border-bottom: none;
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active {
  background: #f3f4f6;
  color: #1f2937;
}

.ts-dropdown .option.selected {
  background: #e5e7eb;
  color: #374151;
}

.ts-dropdown .option.selected.active {
  background: #3b82f6;
  color: white;
}

/* No results and loading states */
.ts-dropdown .no-results,
.ts-dropdown .loading {
  padding: 12px;
  text-align: center;
  color: #6b7280;
  font-style: italic;
  background: #f9fafb;
}

/* Group headers */
.ts-dropdown .optgroup-header {
  padding: 8px 12px;
  background: #f3f4f6;
  color: #4b5563;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e5e7eb;
}

.ts-dropdown .optgroup .option {
  padding-left: 20px;
}

/* Search input in dropdown */
.ts-dropdown .ts-dropdown-content {
  padding: 0;
}

.ts-dropdown input {
  border: none;
  border-bottom: 1px solid #e5e7eb;
  padding: 8px 12px;
  width: 100%;
  font-size: 14px;
  background: #f9fafb;
}

.ts-dropdown input:focus {
  outline: none;
  background: white;
  border-bottom-color: #3b82f6;
}

/* ActiveAdmin specific styles */
.active_admin .ts-control {
  font-size: 13px;
  min-height: 32px;
}

.active_admin .ts-control.single .ts-control {
  padding: 6px 28px 6px 8px;
  height: 32px;
}

.active_admin .ts-control.multi .ts-control {
  padding: 2px 6px;
}

.active_admin .ts-control .item {
  font-size: 12px;
  padding: 1px 6px;
  margin: 1px 2px 1px 0;
}

.active_admin .ts-dropdown .option {
  padding: 6px 10px;
  font-size: 13px;
}

/* Required field styling */
.ts-control.required {
  border-color: #ef4444;
}

.ts-control.required.focus {
  border-color: #dc2626;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.1);
}

/* Invalid state */
.ts-control.invalid {
  border-color: #ef4444;
  background: #fef2f2;
}

.ts-control.invalid.focus {
  border-color: #dc2626;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.1);
}

/* Loading spinner */
.ts-control.loading::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: translateY(-50%) rotate(0deg); }
  100% { transform: translateY(-50%) rotate(360deg); }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .ts-control {
    background: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
  }

  .ts-control input::placeholder {
    color: #9ca3af;
  }

  .ts-control.focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
  }

  .ts-control .item {
    background: #4b5563;
    border-color: #6b7280;
    color: #f3f4f6;
  }

  .ts-control .item.active {
    background: #3b82f6;
    color: white;
  }

  .ts-dropdown {
    background: #374151;
    border-color: #4b5563;
  }

  .ts-dropdown .option {
    color: #f3f4f6;
    border-bottom-color: #4b5563;
  }

  .ts-dropdown .option:hover,
  .ts-dropdown .option.active {
    background: #4b5563;
    color: #f9fafb;
  }

  .ts-dropdown .option.selected {
    background: #6b7280;
    color: #f3f4f6;
  }

  .ts-dropdown .option.selected.active {
    background: #3b82f6;
    color: white;
  }

  .ts-dropdown .no-results,
  .ts-dropdown .loading {
    color: #9ca3af;
    background: #4b5563;
  }

  .ts-dropdown .optgroup-header {
    background: #4b5563;
    color: #d1d5db;
    border-bottom-color: #6b7280;
  }

  .ts-dropdown input {
    background: #4b5563;
    border-bottom-color: #6b7280;
    color: #f3f4f6;
  }

  .ts-dropdown input:focus {
    background: #374151;
    border-bottom-color: #3b82f6;
  }
}
