/*
 * Material picker for the thermal wall calculator (assets/material-picker.js). The picker enhances the plain
 * <select class="th-material" data-material-select> that remains in the form as the no-JS fallback; this file
 * styles only what the script adds: the opener button and the <dialog> it builds. Colours come from the engine
 * tokens so dark mode follows automatically. Hidden in print.
 */

/* The opener replaces the native <select> visually; the <select> stays in the DOM for the form submit. */
.mp-enhanced, .calc-form .field select.mp-enhanced { display: none; }
@media print { .mp-enhanced, .calc-form .field select.mp-enhanced { display: block; } .mp-opener, .mp { display: none !important; } }

.mp-opener {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2);
    width: 100%;
    min-height: 40px;
    padding: 6px 10px;
    text-align: left;
    font: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    cursor: pointer;
}
.mp-opener::after {
    content: "";
    flex: none;
    width: 10px; height: 10px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    opacity: .55;
}
.mp-opener:hover { border-color: var(--c-accent); }
.mp-opener:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.field--error .mp-opener { border-color: var(--c-error); }

/* ---------- The <dialog>: full-screen on phones, centred panel on desktop ---------- */
.mp[open] { display: block; }
.mp {
    position: fixed;
    inset: 2.5vh 0;
    padding: 0;
    border: 0;
    max-width: none;
    width: auto;
    height: 95vh;
    max-height: 95vh;
    background: transparent;
    color: var(--c-text);
}
.mp::backdrop { background: rgba(10, 16, 22, .55); }

.mp__panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--c-surface);
    color: var(--c-text);
    border: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

@media (min-width: 720px) {
    .mp { position: fixed; inset: auto; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 720px; max-width: calc(100vw - 32px); height: 80vh; max-height: 80vh; border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); overflow: hidden; }
    .mp__panel { height: 100%; max-height: 80vh; border-radius: var(--radius-lg); }
}

.mp__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--c-border);
    background: var(--c-surface-alt);
}
.mp__title { margin: 0; font-size: 1.1rem; line-height: 1.2; }
.mp__close {
    appearance: none;
    width: 44px; height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.6rem; line-height: 1;
    background: transparent; border: 0; color: inherit;
    border-radius: var(--radius);
    cursor: pointer;
}
.mp__close:hover { background: var(--c-accent-soft); color: var(--c-link); }
.mp__close:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }

.mp__search { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border); background: var(--c-surface); }
.mp__q {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    font: inherit;
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    box-sizing: border-box;
}
.mp__q:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.mp__count { margin: var(--s-2) 0 0; color: var(--c-muted); font-size: .9rem; }

.mp__body {
    flex: 1 1 auto;
    overflow: auto;
    padding: var(--s-2) var(--s-4) var(--s-4);
    -webkit-overflow-scrolling: touch;
}

.mp__group { border-bottom: 1px solid var(--c-border); }
.mp__group:last-child { border-bottom: 0; }
.mp__group[hidden] { display: none; }
.mp__group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: 10px 4px;
    cursor: pointer;
    list-style: none;
    font-weight: 600;
    min-height: 44px;
}
.mp__group-head::-webkit-details-marker { display: none; }
.mp__group-head::before {
    content: "";
    flex: none;
    width: 8px; height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    opacity: .55;
    transition: transform .15s;
}
details[open] > .mp__group-head::before { transform: rotate(45deg); }
.mp__group-title { flex: 1 1 auto; }
.mp__group-count { color: var(--c-muted); font-weight: 400; font-size: .9rem; }
.mp__group-head:hover { color: var(--c-link); }
.mp__group-head:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; border-radius: var(--radius-sm); }

.mp__list { list-style: none; padding: 0; margin: 0 0 var(--s-2); }
.mp__list li { margin: 0; }
.mp__list li[hidden] { display: none; }

.mp__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    width: 100%;
    min-height: 44px;
    padding: 8px 10px;
    text-align: left;
    font: inherit;
    color: var(--c-text);
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.mp__item:hover, .mp__item.is-hl { background: var(--c-accent-soft); color: var(--c-link); }
.mp__item:focus-visible { outline: 2px solid var(--c-focus); outline-offset: -2px; }
.mp__item.is-current { background: var(--c-accent); color: var(--c-on-accent); }
.mp__item.is-current:hover { background: var(--c-accent); color: var(--c-on-accent); filter: brightness(1.05); }
.mp__item-name { flex: 1 1 auto; }
.mp__item-meta { color: var(--c-muted); font-size: .85rem; white-space: nowrap; }
.mp__item.is-current .mp__item-meta { color: inherit; opacity: .85; }
.mp__item.is-hl .mp__item-meta { color: inherit; }

.mp__empty { padding: var(--s-5) var(--s-4); text-align: center; color: var(--c-muted); }
.mp__empty-hint { display: block; font-size: .9rem; margin-top: var(--s-2); }
