/*
 * MedLookup – Autocomplete Search Styles
 *
 * Scoped to .ml-ac-* to avoid conflicts with themes or other plugins.
 * Override colours via CSS custom properties in your theme:
 *
 *   :root {
 *       --ml-teal:   #0d7d74;
 *       --ml-accent: #c8520e;
 *   }
 */

/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
    --ml-teal:         #0d7d74;
    --ml-teal-light:   #e0f4f2;
    --ml-teal-mid:     #4db5ad;
    --ml-accent:       #c8520e;
    --ml-text:         #1a2e2d;
    --ml-text-mid:     #3d5a59;
    --ml-text-light:   #7a9e9c;
    --ml-border:       #d4e8e6;
    --ml-bg:           #ffffff;
    --ml-hover:        #f4fbfa;
    --ml-active:       #e0f4f2;
    --ml-shadow:       0 4px 20px rgba(13,125,116,0.13);
    --ml-radius:       10px;
    --ml-radius-sm:    6px;
    --ml-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Wrapper ────────────────────────────────────────────────────────────── */
.medlookup-wrap {
    font-family: var(--ml-font);
    position: relative;
    max-width: 600px;
}

.ml-ac-wrap {
    position: relative;
}

/* ── Input row ──────────────────────────────────────────────────────────── */
.ml-ac-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.ml-ac-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ml-teal);
    opacity: 0.55;
    pointer-events: none;
    display: flex;
    align-items: center;
    z-index: 1;
}

.ml-ac-input {
    width: 100%;
    padding: 14px 44px 14px 46px;
    border: 2px solid var(--ml-border);
    border-radius: var(--ml-radius);
    font-family: var(--ml-font);
    font-size: 1rem;
    color: var(--ml-text);
    background: var(--ml-bg);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

/* Remove browser default search cancel button */
.ml-ac-input::-webkit-search-cancel-button,
.ml-ac-input::-webkit-search-decoration {
    -webkit-appearance: none;
}

.ml-ac-input:focus {
    border-color: var(--ml-teal);
    box-shadow: 0 0 0 3px rgba(13,125,116,0.12);
}

.ml-ac-input::placeholder {
    color: var(--ml-text-light);
}

/* When dropdown is open, square off the bottom corners */
.ml-ac-wrap[aria-expanded="true"] .ml-ac-input {
    border-bottom-left-radius:  0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
}

/* ── Clear button ───────────────────────────────────────────────────────── */
.ml-ac-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ml-border);
    border: none;
    border-radius: 50%;
    color: var(--ml-text-mid);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

.ml-ac-clear:hover {
    background: var(--ml-accent);
    color: #fff;
}

/* ── Dropdown ───────────────────────────────────────────────────────────── */
.ml-ac-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--ml-bg);
    border: 2px solid var(--ml-teal);
    border-top: none;
    border-radius: 0 0 var(--ml-radius) var(--ml-radius);
    box-shadow: var(--ml-shadow);
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 360px;
    overflow-y: auto;
    z-index: 9999;
    box-sizing: border-box;

    /* Smooth open animation */
    animation: ml-dropdown-open 0.15s ease;
}

@keyframes ml-dropdown-open {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Result items ───────────────────────────────────────────────────────── */
.ml-ac-item {
    padding: 11px 16px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid #f3f8f8;
}

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

.ml-ac-item:hover,
.ml-ac-item--active {
    background: var(--ml-active);
}

/* Inner flex row */
.ml-ac-item-inner {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 5px;
    width: 100%;
}

/* Brand name shown when query matched a brand (e.g. "Tylenol") */
.ml-ac-brand-match {
    font-size: 0.97rem;
    font-weight: 700;
    color: var(--ml-accent);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Arrow between brand and generic */
.ml-ac-arrow {
    font-size: 0.8rem;
    color: var(--ml-text-light);
    flex-shrink: 0;
}

/* Generic names wrapper */
.ml-ac-names {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

/* Generic name — English */
.ml-ac-name-en {
    font-size: 0.97rem;
    font-weight: 600;
    color: var(--ml-text);
    line-height: 1.3;
}

/* Separator slash */
.ml-ac-sep {
    font-size: 0.8rem;
    color: var(--ml-text-light);
    font-weight: 300;
}

/* Generic name — Spanish */
.ml-ac-name-es {
    font-size: 0.87rem;
    color: var(--ml-text-mid);
    font-style: italic;
    font-weight: 400;
}

/* Drug class badge — pushed to the right */
.ml-ac-class {
    margin-left: auto;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--ml-teal);
    background: var(--ml-teal-light);
    border-radius: 4px;
    padding: 2px 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Highlighted match characters ───────────────────────────────────────── */
.ml-ac-mark {
    background: transparent;
    color: var(--ml-accent);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 2px;
}

/* ── No results ─────────────────────────────────────────────────────────── */
.ml-ac-no-results {
    padding: 14px 16px;
    font-size: 0.88rem;
    color: var(--ml-text-light);
    font-style: italic;
    text-align: center;
    cursor: default;
}

/* ── Status (screen reader) ─────────────────────────────────────────────── */
.ml-ac-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Scrollbar styling (Webkit) ─────────────────────────────────────────── */
.ml-ac-dropdown::-webkit-scrollbar {
    width: 6px;
}
.ml-ac-dropdown::-webkit-scrollbar-track {
    background: transparent;
}
.ml-ac-dropdown::-webkit-scrollbar-thumb {
    background: var(--ml-border);
    border-radius: 3px;
}
.ml-ac-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--ml-text-light);
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media ( max-width: 480px ) {
    .ml-ac-input {
        font-size: 0.95rem;
        padding: 12px 42px 12px 42px;
    }

    .ml-ac-item {
        padding: 10px 14px;
    }

    .ml-ac-class {
        display: none;   /* hide class badge on very small screens */
    }
}
