/* MedXSmart compact multi-select — replaces tall checkbox lists with a dropdown. */

.medx-ms {
    position: relative;
    margin-top: 0.25rem;
    min-width: 0;
}

.medx-ms__trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background: #f9fafb;
    color: #111827;
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.medx-ms__trigger:hover {
    background: #f3f4f6;
}

.medx-ms__trigger:focus-visible,
.medx-ms.is-open .medx-ms__trigger {
    outline: none;
    border-color: var(--primary, #2563eb);
    box-shadow: 0 0 0 1px var(--primary, #2563eb);
}

.medx-ms.has-error .medx-ms__trigger {
    border-color: #ef4444;
}

.medx-ms__value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.medx-ms__value.is-placeholder {
    color: #6b7280;
}

.medx-ms__count {
    flex-shrink: 0;
    min-width: 1.35rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: var(--primary, #2563eb);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
}

.medx-ms__caret {
    flex-shrink: 0;
    width: 0.55rem;
    height: 0.55rem;
    margin-right: 0.15rem;
    border-right: 2px solid #6b7280;
    border-bottom: 2px solid #6b7280;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.15s;
}

.medx-ms.is-open .medx-ms__caret {
    transform: translateY(1px) rotate(-135deg);
}

.medx-ms__panel {
    position: absolute;
    z-index: 45;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    padding: 0.35rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #fff;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.medx-ms__panel[hidden] {
    display: none;
}

.medx-ms.is-flipped .medx-ms__panel {
    top: auto;
    bottom: calc(100% + 0.35rem);
}

.medx-ms__search {
    padding: 0.25rem 0.25rem 0.4rem;
}

.medx-ms__search input {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background: #f9fafb;
    color: #111827;
    font-size: 0.82rem;
    font-family: inherit;
}

.medx-ms__search input:focus {
    outline: none;
    border-color: var(--primary, #2563eb);
    box-shadow: 0 0 0 1px var(--primary, #2563eb);
}

.medx-ms__options {
    max-height: 14.5rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.medx-ms__option {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 2.75rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.5rem;
    color: #1f2937;
    font-size: 0.85rem;
    line-height: 1.35;
    cursor: pointer;
}

.medx-ms__option:hover {
    background: #f1f5f9;
}

.medx-ms__option.is-selected {
    background: #eff6ff;
    font-weight: 600;
}

.medx-ms__option[hidden] {
    display: none;
}

.medx-ms__option input[type="checkbox"] {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    margin: 0;
    border-radius: 0.25rem;
    border: 1px solid #cbd5e1;
    color: var(--primary, #2563eb);
    accent-color: var(--primary, #2563eb);
    cursor: pointer;
}

.medx-ms__empty {
    padding: 0.65rem 0.55rem;
    color: #6b7280;
    font-size: 0.8rem;
    text-align: center;
}

.medx-ms__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.25rem;
    padding: 0.4rem 0.45rem 0.15rem;
    border-top: 1px solid #f1f5f9;
}

.medx-ms__action {
    min-height: 2.5rem;
    padding: 0.35rem 0.55rem;
    border: none;
    background: none;
    color: var(--primary, #2563eb);
    font-size: 0.75rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}

.medx-ms__action:hover {
    text-decoration: underline;
}

.medx-ms__action--muted {
    color: #64748b;
}

@media (max-width: 640px) {
    .medx-ms__trigger {
        min-height: 2.75rem;
        padding: 0.7rem 0.85rem;
    }

    .medx-ms__options {
        max-height: min(14rem, 45vh);
    }

    .medx-ms__option {
        min-height: 2.85rem;
        padding: 0.65rem 0.7rem;
        font-size: 0.9rem;
    }

    .medx-ms__panel {
        left: 0;
        right: 0;
    }
}
