/* Hledání ve vesmíru: jedno pole nahoře místo dřívějších řad čipů (src/ui/Search.js).
   #search měří App.measure(): spodní hrana je --top-off, takže je v něm jen řádek s polem; rozbalený panel je pod ním
   umístěný absolutně. Používá proměnné a třídy z ui.css (--glass, --line, .chip, .chip-dot). */

#search {
    position: absolute;
    top: calc(var(--gutter) + 56px + var(--safe-t));
    left: calc(var(--gutter) + var(--safe-l));
    right: calc(var(--gutter) + var(--safe-r));
    z-index: 8;                         /* nad kartou tělesa (4), pravítkem (3), kartou úkazu (6), pod okny (20) */
    pointer-events: none;
}

.search-box {
    position: relative;
    width: min(460px, 100%);
    margin: 0 auto;
}

/* ---- pole ---- */

.search-field {
    position: relative;
    display: flex;
    align-items: center;
    min-height: var(--hit);
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--line);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: auto;
    transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}

.search-field:hover { border-color: var(--line-strong); }

.search-field:focus-within,
#search.is-open .search-field {
    border-color: var(--accent);
    background: var(--glass-strong);
    box-shadow: 0 0 0 3px rgba(124, 199, 255, 0.22);
}

.search-lupa {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 42px;
    align-self: stretch;
    color: var(--text-dim);
}

.search-field:focus-within .search-lupa { color: var(--accent); }

.search-input {
    flex: 1 1 auto;
    min-width: 0;
    height: calc(var(--hit) - 2px);
    padding: 0 6px 0 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font-size: 16px;                    /* méně by iPhone při zaostření přiblížil stránku */
    font-weight: 500;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    text-overflow: ellipsis;
}

.search-input::placeholder { color: var(--text-dim); opacity: 1; }
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration { -webkit-appearance: none; display: none; }

/* vybrané těleso: tečka a jméno místo zástupného textu, po zaostření pole ustoupí psaní */
.search-sel {
    position: absolute;
    left: 42px;
    right: 44px;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 16px;
    font-weight: 600;
    pointer-events: none;
}

.search-sel-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-field:focus-within .search-sel,
.search-field.has-value .search-sel { display: none; }
.search-field.has-sel:not(:focus-within) .search-input::placeholder { color: transparent; }

.search-clear {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    margin-right: 3px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-dim);
}

.search-clear:hover { background: rgba(255, 255, 255, 0.12); color: var(--text); }

/* ---- rozbalený panel ---- */

.search-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    max-height: 60vh;                   /* přepíše Search._layout podle volného místa */
    display: flex;
    flex-direction: column;
    background: var(--glass-strong);
    border: 1px solid var(--line-strong);
    border-radius: 22px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    pointer-events: auto;
}

.search-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 6px 10px 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

/* ---- skupiny bez dotazu ---- */

.search-group + .search-group { margin-top: 10px; }

.search-group-title {
    margin: 6px 4px 6px;
    font-family: var(--main-font);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.search-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.search-chip {
    cursor: pointer;
    min-height: 38px;
    padding: 0 13px 0 10px;
    gap: 7px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.07);
    backdrop-filter: none;              /* panel už rozmazává pozadí, desítky dalších filtrů by zbytečně zpomalovaly */
    -webkit-backdrop-filter: none;
    user-select: none;
    -webkit-user-select: none;
}

@media (pointer: coarse) { .search-chip { min-height: 42px; } }

.search-chip .icon { color: var(--c, var(--accent)); flex: 0 0 auto; }
.search-chip.is-active .icon { color: inherit; }
.search-chip.is-hl { outline: 2px solid var(--accent); outline-offset: 1px; }

.search-chip-n {
    display: inline-grid;
    place-items: center;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    background: rgba(124, 199, 255, 0.2);
    color: var(--accent);
}

.search-chip.is-active .search-chip-n { background: rgba(4, 18, 31, 0.2); color: inherit; }
.search-chip-sub { font-size: 11.5px; font-weight: 500; color: var(--text-dim); }
.search-chip.is-active .search-chip-sub { color: inherit; opacity: 0.8; }

/* ---- výsledky ---- */

.search-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 48px;
    padding: 9px 12px;
    border-radius: 14px;
    cursor: pointer;
}

.search-item:hover { background: rgba(124, 199, 255, 0.1); }
.search-item.is-hl { background: rgba(124, 199, 255, 0.16); box-shadow: inset 0 0 0 1px rgba(124, 199, 255, 0.55); }

.search-ico {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin-top: 1px;
    border-radius: 50%;
    background: rgba(124, 199, 255, 0.12);
    box-shadow: inset 0 0 0 1px rgba(124, 199, 255, 0.3);
    color: var(--c, var(--accent));
}

.search-ico--dot { background: transparent; box-shadow: none; }
.search-ico--dot .chip-dot { width: 14px; height: 14px; }

.search-item-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.search-item-name { font-size: 15px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.search-item-sub { font-size: 12.5px; line-height: 1.35; color: var(--text-dim); overflow-wrap: anywhere; }
.search-item-snip { margin-top: 2px; font-size: 13px; line-height: 1.4; color: var(--text); opacity: 0.88; overflow-wrap: anywhere; }

.search-panel mark {
    background: rgba(255, 211, 92, 0.3);
    color: #fff;
    border-radius: 3px;
    padding: 0 1px;
}

.search-empty {
    margin: 0;
    padding: 18px 12px;
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-dim);
}

@keyframes search-in { from { opacity: 0; } }
.search-panel { animation: search-in 0.14s ease-out; }

/* ---- rozvržení ---- */

/* široká obrazovka: panel je širší než pole (míň řádků čipů, delší úryvky), vystředěný pod ním */
@media (min-width: 821px) {
    .search-panel {
        left: 50%;
        right: auto;
        width: min(620px, calc(100vw - 2 * var(--gutter) - var(--safe-l) - var(--safe-r)));
        transform: translateX(-50%);
    }
}

/* telefon a tablet na výšku: pole přes celou šířku mezi okraji */
@media (max-width: 820px) {
    .search-box { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .search-panel { animation: none; }
}

/* nízká obrazovka (telefon na šířku): nižší pole a čipy, ať zbyde místo na model */
@media (max-height: 520px) {
    #search { top: calc(var(--gutter) + 50px + var(--safe-t)); }
    .search-box { width: min(420px, 100%); }
    .search-field { min-height: 40px; }
    .search-input { height: 38px; }
    .search-chip { min-height: 34px; font-size: 13.5px; }
    .search-item { min-height: 42px; padding: 6px 10px; }
}

/* telefon na šířku s dost místem do šířky: pole je ve volné části horní lišty mezi značkou a tlačítky, další řádek se nespotřebuje */
@media (max-height: 520px) and (min-width: 720px) {
    #search {
        top: calc(var(--gutter) - 2px + var(--safe-t) + 7px);
        left: calc(var(--gutter) + var(--safe-l) + 144px);
        right: calc(var(--gutter) + var(--safe-r) + 266px);
    }
}
