/*
 * MedLookup – Body diagram lookup ([rankd_mlk_body])
 *
 * Scoped to .rankd-mlk-*. Inherits the theme's font. Override colours in
 * your theme:
 *
 *   .rankd-mlk-body { --rankd-mlk-active: #f5a524; --rankd-mlk-es: #0d7d74; }
 */

.rankd-mlk-body {
    --rankd-mlk-ink:         #1f2a37;
    --rankd-mlk-muted:       #5b6b7d;
    --rankd-mlk-line:        #d5dde6;
    --rankd-mlk-panel:       #ffffff;
    --rankd-mlk-chip:        #eef3f7;
    --rankd-mlk-part:        #dbe4ee;
    --rankd-mlk-part-stroke: #5b6b7d;
    --rankd-mlk-body-fill:   #eef2f6;
    --rankd-mlk-body-stroke: #a9b5c2;
    --rankd-mlk-hover:       #fde68a;
    --rankd-mlk-active:      #f5a524;
    --rankd-mlk-es:          #0d7d74;   /* matches the drug search teal */

    display: grid;
    grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
    grid-template-areas:
        "figure search"
        "figure card"
        "figure list"
        "figure disclaimer";
    grid-template-rows: auto auto 1fr auto;
    gap: 16px 32px;
    align-items: start;
    color: var(--rankd-mlk-ink);
    line-height: 1.45;
    max-width: 1080px;
    margin: 0 auto;
}
.rankd-mlk-body *, .rankd-mlk-body *::before, .rankd-mlk-body *::after { box-sizing: border-box; }

.rankd-mlk-search     { grid-area: search; position: relative; }
.rankd-mlk-figure     { grid-area: figure; position: sticky; top: 16px; }
.rankd-mlk-card       { grid-area: card; }
.rankd-mlk-list       { grid-area: list; }
.rankd-mlk-disclaimer { grid-area: disclaimer; }

/* ── Search ─────────────────────────────────────────────────────────────── */
.rankd-mlk-search label { display: block; font-weight: 700; margin-bottom: 6px; }
.rankd-mlk-search input[type="search"] {
    width: 100%; font: inherit; font-size: max(16px, 1em);   /* 16px stops iOS zoom */
    padding: 12px 14px; border-radius: 10px;
    border: 1.5px solid var(--rankd-mlk-line); background: var(--rankd-mlk-panel); color: var(--rankd-mlk-ink);
}
.rankd-mlk-search input[type="search"]:focus {
    outline: 3px solid color-mix(in srgb, var(--rankd-mlk-es) 35%, transparent);
    border-color: var(--rankd-mlk-es);
}
.rankd-mlk-suggest {
    list-style: none; margin: 6px 0 0; padding: 0;
    border: 1px solid var(--rankd-mlk-line); border-radius: 10px; background: var(--rankd-mlk-panel); overflow: hidden;
}
.rankd-mlk-suggest[hidden] { display: none; }
.rankd-mlk-suggest li { margin: 0; padding: 0; }
.rankd-mlk-suggest li + li { border-top: 1px solid var(--rankd-mlk-line); }
.rankd-mlk-suggest button {
    display: block; width: 100%; text-align: left; font: inherit; color: inherit;
    background: none; border: 0; border-radius: 0; padding: 10px 14px; cursor: pointer; margin: 0;
}
.rankd-mlk-suggest button:hover, .rankd-mlk-suggest button:focus-visible { background: var(--rankd-mlk-chip); outline: none; }
.rankd-mlk-via { color: var(--rankd-mlk-muted); font-size: .9em; }
.rankd-mlk-ask { margin: 8px 0 0; color: var(--rankd-mlk-muted); }

/* ── View buttons ───────────────────────────────────────────────────────── */
.rankd-mlk-views { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.rankd-mlk-views button {
    font: inherit; font-size: .88em; line-height: 1.2; text-align: left;
    padding: 6px 12px; border-radius: 999px; cursor: pointer; margin: 0;
    border: 1px solid var(--rankd-mlk-line); background: var(--rankd-mlk-panel); color: var(--rankd-mlk-ink);
}
.rankd-mlk-views button span { display: block; font-size: .85em; color: var(--rankd-mlk-muted); }
.rankd-mlk-views button[aria-pressed="true"] { background: var(--rankd-mlk-ink); border-color: var(--rankd-mlk-ink); color: #fff; }
.rankd-mlk-views button[aria-pressed="true"] span { color: rgba(255,255,255,.75); }
.rankd-mlk-views button:focus-visible { outline: 2px solid var(--rankd-mlk-es); outline-offset: 2px; }

/* ── Diagram ────────────────────────────────────────────────────────────── */
.rankd-mlk-diagram-wrap svg { display: block; width: 100%; height: auto; max-height: 78vh; margin: 0 auto; overflow: visible; }
.rankd-mlk-body .rankd-mlk-part {
    fill: var(--rankd-mlk-part); stroke: var(--rankd-mlk-part-stroke); stroke-width: 1.2;
    cursor: pointer; transition: fill .15s;
}
.rankd-mlk-body .rankd-mlk-part.rankd-mlk-dark { fill: color-mix(in srgb, var(--rankd-mlk-part-stroke) 70%, var(--rankd-mlk-part)); }
.rankd-mlk-body .rankd-mlk-context { fill: var(--rankd-mlk-body-fill); stroke: var(--rankd-mlk-body-stroke); stroke-width: 1; }
.rankd-mlk-body .rankd-mlk-hit { fill: transparent !important; stroke: none; }
.rankd-mlk-body .rankd-mlk-deco { fill: none !important; stroke: var(--rankd-mlk-part-stroke); stroke-width: 1; pointer-events: none; }
.rankd-mlk-body .rankd-mlk-frame { fill: none; stroke: var(--rankd-mlk-line); stroke-width: 1; }
@media (hover: hover) {
    .rankd-mlk-body .rankd-mlk-part:hover { fill: var(--rankd-mlk-hover); }
}
.rankd-mlk-body .rankd-mlk-part.is-active,
.rankd-mlk-body .rankd-mlk-group.is-active .rankd-mlk-part { fill: var(--rankd-mlk-active); }
.rankd-mlk-body .rankd-mlk-part:focus { outline: none; }
.rankd-mlk-body .rankd-mlk-part:focus-visible { stroke: var(--rankd-mlk-ink); stroke-width: 2.5; }

.rankd-mlk-caption { margin-top: 8px; color: var(--rankd-mlk-muted); font-size: .9em; text-align: center; }
.rankd-mlk-caption p { margin: 2px 0; }
.rankd-mlk-caption span { font-style: italic; }

/* ── Card ───────────────────────────────────────────────────────────────── */
.rankd-mlk-card {
    background: var(--rankd-mlk-panel); border: 1px solid var(--rankd-mlk-line);
    border-left: 5px solid var(--rankd-mlk-active); border-radius: 10px;
    padding: 14px 16px; min-height: 96px;
}
.rankd-mlk-card p { margin: 6px 0 0; }
.rankd-mlk-card p:first-child { margin-top: 0; }
.rankd-mlk-card-empty { color: var(--rankd-mlk-muted); }
.rankd-mlk-card .rankd-mlk-card-en { font-size: 1.35em; font-weight: 700; margin: 0; line-height: 1.2; }
.rankd-mlk-card .rankd-mlk-card-es { font-size: 1.35em; color: var(--rankd-mlk-es); margin: 0 0 4px; line-height: 1.25; }
.rankd-mlk-meta { color: var(--rankd-mlk-muted); font-size: .92em; }

/* ── Term list ──────────────────────────────────────────────────────────── */
.rankd-mlk-list h2 { font-size: 1.05em; margin: 0 0 8px; }
.rankd-mlk-terms {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px;
}
.rankd-mlk-terms li { margin: 0; padding: 0; }
.rankd-mlk-terms button {
    display: block; width: 100%; text-align: left; font: inherit; color: inherit; margin: 0;
    padding: 8px 12px; border-radius: 8px; cursor: pointer;
    background: var(--rankd-mlk-chip); border: 1px solid transparent;
}
.rankd-mlk-terms button:hover { border-color: var(--rankd-mlk-line); background: var(--rankd-mlk-chip); color: inherit; }
.rankd-mlk-terms button:focus-visible { outline: 2px solid var(--rankd-mlk-es); }
.rankd-mlk-terms button[aria-pressed="true"] {
    border-color: var(--rankd-mlk-active);
    background: color-mix(in srgb, var(--rankd-mlk-active) 18%, var(--rankd-mlk-chip));
}
.rankd-mlk-t-en { display: block; }
.rankd-mlk-t-es { display: block; color: var(--rankd-mlk-es); font-size: .92em; }
.rankd-mlk-suggest .rankd-mlk-t-en, .rankd-mlk-suggest .rankd-mlk-t-es { display: inline; }

.rankd-mlk-disclaimer { color: var(--rankd-mlk-muted); font-size: .85em; margin: 0; }

/* ── Desktop tooltip ────────────────────────────────────────────────────── */
.rankd-mlk-tip {
    position: fixed; z-index: 99999; display: none; pointer-events: none;
    background: #1f2a37; color: #fff; padding: 6px 10px; border-radius: 8px;
    font-size: 14px; line-height: 1.3; max-width: 240px;
}
.rankd-mlk-tip strong { display: block; }

/* ── Phones: search, diagram, then a card that sticks to the bottom edge ── */
@media (max-width: 760px) {
    .rankd-mlk-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "search" "figure" "card" "list" "disclaimer";
        grid-template-rows: none;
        gap: 14px;
    }
    .rankd-mlk-figure { position: static; }
    .rankd-mlk-diagram-wrap svg { max-height: 82vh; }
    .rankd-mlk-views {
        flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
        -webkit-overflow-scrolling: touch; padding-bottom: 2px;
    }
    .rankd-mlk-views::-webkit-scrollbar { display: none; }
    .rankd-mlk-views button { flex: 0 0 auto; }
    .rankd-mlk-card {
        position: sticky; bottom: 0; z-index: 5;
        margin: 0 -4px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 18px rgba(0, 0, 0, .12);
        max-height: 45vh; overflow-y: auto; overscroll-behavior: contain;
    }
    .rankd-mlk-card .rankd-mlk-card-en, .rankd-mlk-card .rankd-mlk-card-es { font-size: 1.15em; }
}

@media (prefers-reduced-motion: reduce) {
    .rankd-mlk-body .rankd-mlk-part { transition: none; }
}
