/* =========================================================================
   Search popup (command palette) and the /search results page.
   Uses the sg-* tokens from segasoft.css. Works on modern and legacy pages.
   ========================================================================= */
html.sgs-open { overflow: hidden; }

.sgs { position: fixed; inset: 0; z-index: 2000; display: flex; justify-content: center; align-items: flex-start; padding: 0; font-family: var(--sg-font); }
.sgs[hidden], .sgs [hidden] { display: none !important; }
.sgs *, .sgs *::before, .sgs *::after { box-sizing: border-box; }

.sgs__backdrop { position: absolute; inset: 0; background: rgba(10, 20, 40, .55); -webkit-backdrop-filter: blur(6px) saturate(140%); backdrop-filter: blur(6px) saturate(140%); opacity: 0; transition: opacity .18s ease; }
.sgs.is-open .sgs__backdrop { opacity: 1; }

.sgs__panel {
    position: relative; display: flex; flex-direction: column; width: 100%; height: 100%; max-height: 100dvh;
    background: #fff; box-shadow: 0 30px 80px -20px rgba(10, 20, 40, .45), 0 0 0 1px rgba(10, 20, 40, .06);
    opacity: 0; transform: translateY(-8px) scale(.985); transition: opacity .18s ease, transform .2s cubic-bezier(.2, .8, .2, 1);
}
.sgs.is-open .sgs__panel { opacity: 1; transform: none; }

/* ---------- Search bar ---------- */
.sgs__bar { position: relative; display: flex; align-items: center; gap: 10px; flex: none; padding: 12px 14px; border-bottom: 1px solid var(--sg-border); }
.sgs__icon { display: inline-flex; color: var(--sg-blue); }
.sgs__icon .sg-i { width: 22px; height: 22px; }
.sgs__input { flex: 1 1 auto; min-width: 0; height: 48px; padding: 0; border: 0; outline: none; background: transparent; color: var(--sg-navy); font: 500 1.12rem var(--sg-font); letter-spacing: -.01em; }
.sgs__input::placeholder { color: #94a3b8; }
.sgs__input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.sgs__spinner { flex: none; width: 18px; height: 18px; border: 2px solid #dbe3f0; border-top-color: var(--sg-blue); border-radius: 50%; animation: sgs-spin .7s linear infinite; }
@keyframes sgs-spin { to { transform: rotate(360deg); } }
.sgs__kbd { display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 6px; border: 1px solid var(--sg-border); border-bottom-width: 2px; border-radius: 6px; background: #f8fafc; color: var(--sg-muted); font: 600 .72rem var(--sg-font); }
.sgs__kbd--esc { display: none; }
.sgs__close { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 10px; background: #f1f5f9; color: var(--sg-navy); cursor: pointer; }
.sgs__close:hover { background: #e2e8f0; }

/* ---------- Body ---------- */
.sgs__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px 14px; }
.sgs__label { display: flex; align-items: center; justify-content: space-between; margin: 12px 8px 8px; color: var(--sg-muted); font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.sgs__clear { padding: 2px 6px; border: 0; background: none; color: var(--sg-blue); font: 600 .78rem var(--sg-font); letter-spacing: 0; text-transform: none; cursor: pointer; }
.sgs__chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 6px; }
.sgs__chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--sg-border); border-radius: 999px; background: #fff; color: var(--sg-navy); font: 550 .88rem var(--sg-font); cursor: pointer; transition: border-color .15s, background-color .15s; }
.sgs__chip .sg-i { width: 14px; height: 14px; color: var(--sg-muted); }
.sgs__chip:hover { border-color: #b8c7e6; background: var(--sg-blue-soft); }

.sgs__quick { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 0; padding: 0 2px; list-style: none; }
.sgs__tile { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid transparent; border-radius: 14px; color: var(--sg-navy); text-decoration: none !important; transition: background-color .15s, border-color .15s; }
.sgs__tile:hover, .sgs__tile:focus-visible { background: #f8fafc; border-color: var(--sg-border); }
.sgs__tile-icon { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--sg-blue-soft); color: var(--sg-blue); }
.sgs__tile-text { display: flex; flex-direction: column; min-width: 0; }
.sgs__tile-text strong { font-size: .95rem; font-weight: 650; }
.sgs__tile-text small { overflow: hidden; color: var(--sg-muted); font-size: .82rem; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- Results ---------- */
.sgs__group + .sgs__group { margin-top: 4px; }
.sgs__item { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; color: var(--sg-navy); text-decoration: none !important; scroll-margin: 8px; }
.sgs__item.is-active { background: var(--sg-blue-soft); }
.sgs__item.is-active::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--sg-blue); }
.sgs__item-media { flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: #f1f5f9; color: var(--sg-navy); overflow: hidden; }
.sgs__item-media.has-image { background: #fff; border: 1px solid var(--sg-border); }
.sgs__item-media img { width: 100%; height: 100%; object-fit: cover; }
.sgs__item.is-active .sgs__item-media:not(.has-image) { background: #fff; color: var(--sg-blue); }
.sgs__item-body { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; }
.sgs__item-title { overflow: hidden; font-size: .98rem; font-weight: 650; line-height: 1.3; white-space: nowrap; text-overflow: ellipsis; }
.sgs__item-desc { display: -webkit-box; overflow: hidden; color: var(--sg-muted); font-size: .84rem; line-height: 1.4; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.sgs__item mark { padding: 0 1px; border-radius: 3px; background: #fde68a; color: inherit; }
.sgs__item-meta { flex: none; padding: 3px 9px; border-radius: 999px; background: #ecfdf5; color: #047857; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.sgs__item-go { flex: none; display: inline-flex; color: var(--sg-blue); opacity: 0; transform: translateX(-4px); transition: opacity .15s, transform .15s; }
.sgs__item.is-active .sgs__item-go { opacity: 1; transform: none; }

.sgs__state { padding: 44px 20px; color: var(--sg-muted); text-align: center; }
.sgs__state strong { display: block; margin-bottom: 4px; color: var(--sg-navy); font-size: 1.02rem; }
.sgs__state p { margin: 0; }
.sgs__state a { color: var(--sg-blue); font-weight: 600; }
.sgs__state-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: 50%; background: #f1f5f9; color: #94a3b8; }

/* ---------- Footer ---------- */
.sgs__foot { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--sg-border); background: #f8fafc; color: var(--sg-muted); font-size: .8rem; }
.sgs__hints { display: none; align-items: center; gap: 5px; }
.sgs__hints .sgs__kbd + .sgs__kbd { margin-left: -1px; }
.sgs__all { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; color: var(--sg-blue); font-weight: 650; text-decoration: none; }
.sgs__all:hover { text-decoration: underline; }
.sgs__all .sg-i { width: 16px; height: 16px; }

/* ---------- Desktop: floating panel ---------- */
@media (min-width: 720px) {
    .sgs { padding: 10vh 20px 20px; }
    .sgs__panel { height: auto; max-width: 680px; max-height: min(620px, 80vh); border-radius: 20px; overflow: hidden; }
    .sgs__bar { padding: 10px 14px 10px 20px; }
    .sgs__input { height: 56px; font-size: 1.2rem; }
    .sgs__kbd--esc { display: inline-grid; }
    .sgs__close { display: none; }
    .sgs__quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sgs__hints { display: inline-flex; }
    .sgs__foot { padding-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .sgs__backdrop, .sgs__panel, .sgs__item-go { transition: none; }
    .sgs__spinner { animation-duration: 1.6s; }
}

/* ---------- /search page ---------- */
.sr-hero { padding: 40px 0 32px; }
.sr-hero h1 { margin: 0 0 18px; }
.sr-form { position: relative; display: flex; gap: 8px; max-width: 720px; }
.sr-form__icon { position: absolute; left: 16px; top: 50%; display: inline-flex; color: var(--sg-muted); transform: translateY(-50%); pointer-events: none; }
.sr-form input { flex: 1 1 auto; min-width: 0; min-height: 54px; padding: 10px 16px 10px 46px; border: 1.5px solid #cbd5e1; border-radius: 999px; background: #fff; color: var(--sg-navy); font: 500 1.05rem var(--sg-font); }
.sr-form input:focus { outline: none; border-color: var(--sg-blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
.sr-form .sg-btn { flex: none; min-height: 54px; }
.sr-section { padding: 32px 0 80px; }
.sr-count { margin: 0 0 18px; color: var(--sg-muted); }
.sr-count strong { color: var(--sg-navy); }
.sr-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; max-width: 860px; }
.sr-item { display: flex; gap: 16px; align-items: flex-start; padding: 16px 18px; border: 1px solid var(--sg-border); border-radius: 16px; background: #fff; color: var(--sg-navy); text-decoration: none !important; transition: border-color .15s, box-shadow .15s; }
.sr-item:hover { border-color: #cdd6e3; box-shadow: var(--sg-shadow); }
.sr-item__media { flex: none; display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 14px; background: var(--sg-blue-soft); color: var(--sg-blue); overflow: hidden; }
.sr-item__media img { width: 100%; height: 100%; object-fit: cover; }
.sr-item__body { min-width: 0; }
.sr-item__cat { display: inline-block; margin-bottom: 4px; color: var(--sg-muted); font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sr-item__title { display: block; margin-bottom: 4px; font-size: 1.08rem; font-weight: 650; }
.sr-item__desc { display: block; margin: 0; color: var(--sg-text); font-size: .94rem; line-height: 1.5; }
.sr-item__meta { display: inline-block; margin-top: 6px; padding: 2px 9px; border-radius: 999px; background: #ecfdf5; color: #047857; font-size: .8rem; font-weight: 700; }
.sr-empty { max-width: 640px; padding: 32px; border: 1px dashed #cbd5e1; border-radius: 18px; background: #f8fafc; }
.sr-empty h2 { margin: 0 0 6px; font-size: 1.25rem; }
.sr-empty p { margin: 0 0 14px; color: var(--sg-muted); }
.sr-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sr-chips a { padding: 7px 14px; border: 1px solid var(--sg-border); border-radius: 999px; background: #fff; color: var(--sg-navy); font-size: .9rem; font-weight: 600; text-decoration: none; }
.sr-chips a:hover { border-color: var(--sg-blue); color: var(--sg-blue); }
@media (min-width: 900px) { .sr-hero { padding: 64px 0 44px; } }
