/* Autocomplete CSS - Reusable across projects */

.autocomplete {
  position: relative;
  display: block;
  /* width: 100%; */
}

/* --- FIX: Add loading state style --- */
.autocomplete-loading {
    position: relative;
}

.autocomplete-loading::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-top-color: #007cba;
    border-radius: 50%;
    animation: autocomplete-spin 0.8s linear infinite;
    z-index: 10;
}

/* Hide controls when loading */
.autocomplete-loading .refresh-button,
.autocomplete-loading .edit-button {
    display: none;
}

/* Specific for textarea, place spinner inside */
.autocomplete-loading textarea {
    padding-right: 30px; /* Space for spinner */
}

.autocomplete-loading textarea + .refresh-button,
.autocomplete-loading textarea + .edit-button {
    display: none; /* Hide controls if they are siblings */
}

@keyframes autocomplete-spin {
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}
/* --- END FIX --- */


.autocomplete-items {
  position: absolute;
  border: 1px solid #d4d4d4;
  z-index: 9999;
  /*top: 100%; Set dynamically */
  /*left: 0; Set dynamically */
  /*width: 100%; Set dynamically */
  max-height: 250px;
  overflow-y: auto;
  border-radius: 0 0 5px 5px;
  background-color: #fff;
  box-sizing: border-box;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.autocomplete-items .sizer {
    position: relative;
    width: 100%;
}

.autocomplete-items .sizer > div {
    position: absolute;
    width: 100%;
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #d4d4d4; 
    box-sizing: border-box; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color: #fff;
}

/* Hover effects */
.autocomplete-items .sizer > div:hover {
  background-color: #e9e9e9; 
}

/* Active selection (keyboard navigation) */
.autocomplete-active {
  background-color: #007cba !important; 
  color: #ffffff !important; 
}

/* Multi-select container */
.autocomplete-multiselect-container {
    min-height: 40px;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 5px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    background-color: white;
}

.autocomplete-multiselect-container input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 100px;
    padding: 5px;
}

/* Selected items (tags) */
.selected-item {
    background-color: #007cba;
    color: white;
    padding: 3px 8px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

.remove-item {
    cursor: pointer;
    font-weight: bold;
    background-color: rgba(255,255,255,0.3);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.remove-item:hover {
    background-color: rgba(255,255,255,0.5);
}

/* Control buttons */
.has-controls {
    position: relative;
}

.has-controls input[type=text] {
    padding-right: 70px; /* Space for two icons */
}

/* --- FIX: Add rule for textareas --- */
.has-controls textarea {
    padding-right: 70px; /* Space for two icons */
}

.has-controls .autocomplete-multiselect-container {
    padding-right: 70px; /* Space for two icons */
}

.refresh-button, .edit-button {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 16px;
    color: #666;
    background: transparent;
    border: none;
    padding: 5px;
    z-index: 10;
}

.refresh-button {
    right: 35px;
}

.edit-button {
    right: 10px;
}

.refresh-button:hover, .edit-button:hover {
    color: #007cba;
}

.refresh-button.loading {
    animation: spin 1s linear infinite;
    color: #007cba !important;
}

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

/* Error states */
.autocomplete input[placeholder*="Failed"],
.autocomplete input[placeholder*="Error"],
.autocomplete input[placeholder*="error"] {
    border-color: #dc3545;
    background-color: #fff5f5;
}

/* Success state for refresh */
.refresh-button.success {
    color: #28a745 !important;
}

.has-selection .refresh-button,
.has-selection .edit-button {
    color: #007cba;
}

/* Tooltip */
#autocomplete-tooltip {
    position: absolute;
    background-color: #333;
    color: white;
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 10000;
    display: none;
    max-width: 300px;
    word-wrap: break-word;
    pointer-events: none;
}

/* Input styling */
input[type=text] {
    background-color: #fff;
    width: 100%;
    border: 1px solid #ccc;
    padding: 10px;
    font-size: 16px;
    border-radius: 5px;
}

input[type=submit] {
    background-color: #007bff;
    color: #fff;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    padding: 10px 15px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .autocomplete-items {
        max-height: 200px;
    }
    
    .autocomplete-multiselect-container {
        min-height: 35px;
        padding: 3px;
    }
    
    .selected-item {
        font-size: 11px;
        padding: 2px 6px;
    }
}

