/* Autocomplete Dropdown Styles */

.autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 60vh;  /* Use viewport height to prevent overflow */
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin: 0 0 2rem 0;  /* Add bottom margin for spacing */
    padding: 0;
    list-style: none;
}

.autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.15s ease;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background-color: #f5f5f5;
}

.autocomplete-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.autocomplete-celex {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    font-family: var(--font-stack-mono);
}

.autocomplete-acronym {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    background: var(--lx-surface-inset);
    padding: 2px 6px;
    border-radius: 3px;
}

.autocomplete-title {
    font-size: 14px;
    color: #555;
    margin-bottom: 4px;
    line-height: 1.4;
}

.autocomplete-meta {
    font-size: 12px;
    color: #999;
    line-height: 1.3;
}

/* Literal-tier section header (Statutory Instruments, #705) */
.autocomplete-section-header {
    padding: 8px 16px 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #999;
    background: #fafafa;
    border-top: 1px solid #f0f0f0;
}

/* Rows are links (#3922): keep the row look, drop the link look */
a.autocomplete-item {
    display: block;
    color: inherit;
    text-decoration: none;
}

/* UK catalogue entry not ingested yet: it opens on Lex-Ray and is prepared on first open */
.autocomplete-pending {
    font-size: 11px;
    color: #0066cc;
    white-space: nowrap;
    margin-left: auto;
    padding-left: 8px;
}

/* The chosen row says it is working; the rest of the list stops taking clicks.
 * The words come from a pseudo-element, so no class here hides text. */
.autocomplete-dropdown.is-opening {
    pointer-events: none;
}

.autocomplete-item[aria-busy="true"] {
    background-color: #e7f3ff;
}

.autocomplete-item[aria-busy="true"] .autocomplete-header::after {
    content: "Opening…";
    font-size: 11px;
    color: #0066cc;
    white-space: nowrap;
    margin-left: 8px;
}

/* Highlight matching text */
.autocomplete-item mark {
    background-color: var(--lx-warning-bg);
    color: inherit;
    font-weight: 600;
    padding: 0 2px;
    border-radius: 2px;
}

/* Focus and keyboard navigation */
.autocomplete-item.selected {
    background-color: #e7f3ff;
    outline: 2px solid #0066cc;
    outline-offset: -2px;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .autocomplete-dropdown {
        max-height: 50vh;  /* Smaller on mobile */
    }

    .autocomplete-item {
        padding: 10px 12px;
    }

    .autocomplete-celex {
        font-size: 13px;
    }

    .autocomplete-title {
        font-size: 13px;
    }
}

/* Ensure the dropdown has breathing room from viewport edges */
@media (max-height: 600px) {
    .autocomplete-dropdown {
        max-height: 40vh;  /* Even smaller on short screens */
    }
}

/* Loading state */
.autocomplete-loading {
    padding: 16px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

/* No results state */
.autocomplete-no-results {
    padding: 16px;
    text-align: center;
    color: #666;
    font-size: 14px;
}
