/* ============================================================
   search.css — the command palette: one search across everything
   Global component. Loaded on every page after shelf.css.

   The site had three separate search boxes (/prompts, /tools,
   /news) and none at all on Learn — 771 lessons, the most-read
   section. This is the surface that looks across all of it.

   z-index ladder it has to live inside:
     60   .cmp-tray
     100  .site-header
     8000 .shelf-pill
     8600 .shelf-drawer
     8800 .pal-scrim / .pal-panel     ← above the shelf drawer
     9000 .lp-sheet    (AI chooser — opened FROM a palette result)
     9100 .lp-toast
   Added 2026-11-18 (pass 006).
   ============================================================ */

/* ── The trigger in the nav ─────────────────────────────────── */

.nav-search {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    height: 34px;
    padding: 0 10px 0 12px;
    margin-left: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    cursor: pointer;
    flex: 0 0 auto;
    white-space: nowrap;
    transition: color var(--transition-fast), border-color var(--transition-fast),
                background var(--transition-fast);
}

.nav-search:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: var(--surface-3);
}

.nav-search:focus-visible {
    outline: 2px solid var(--accent-orange);
    outline-offset: 2px;
}

.nav-search-ic { font-size: 0.9rem; line-height: 1; }

.nav-search-kbd {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-faint);
    font-family: var(--font-display);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* The nav collapses to a hamburger at 960px, but search should stay
   reachable — so the trigger shrinks to its icon instead of hiding. */
@media (max-width: 960px) {
    .nav-search {
        margin-left: auto;
        margin-right: var(--space-3);
        width: 34px;
        padding: 0;
        justify-content: center;
    }

    .nav-search-label,
    .nav-search-kbd { display: none; }
}

/* ── Scrim + panel ──────────────────────────────────────────── */

.pal-scrim {
    position: fixed;
    inset: 0;
    z-index: 8800;
    background: rgba(4, 5, 12, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.pal-scrim.is-open { opacity: 1; pointer-events: auto; }

.pal-panel {
    position: fixed;
    z-index: 8800;
    top: 11vh;
    left: 50%;
    width: min(680px, calc(100vw - var(--space-8)));
    max-height: 72vh;
    transform: translate(-50%, -12px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 92, 53, 0.08);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base), transform var(--transition-base);
}

.pal-panel.is-open {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

/* ── Input row ──────────────────────────────────────────────── */

.pal-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.pal-head-ic {
    font-size: var(--text-lg);
    line-height: 1;
    color: var(--text-muted);
    flex: 0 0 auto;
}

.pal-input {
    appearance: none;
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
    padding: 2px 0;
}

.pal-input::placeholder { color: var(--text-faint); font-weight: 500; }
.pal-input:focus { outline: none; }

.pal-spin {
    width: 15px;
    height: 15px;
    border: 2px solid var(--border-hover);
    border-top-color: var(--accent-orange);
    border-radius: 50%;
    animation: palSpin 0.7s linear infinite;
    flex: 0 0 auto;
}

.pal-spin[hidden] { display: none; }

@keyframes palSpin { to { transform: rotate(360deg); } }

.pal-esc {
    appearance: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-faint);
    font-family: var(--font-display);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 3px 7px;
    cursor: pointer;
    flex: 0 0 auto;
}

.pal-esc:hover { color: var(--text); border-color: var(--border-hover); }

/* ── Results ────────────────────────────────────────────────── */

.pal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-2) 0 var(--space-2);
}

.pal-group-label {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5) var(--space-2);
    background: var(--surface);
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.pal-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    width: 100%;
    padding: 10px var(--space-5);
    border: 0;
    border-left: 2px solid transparent;
    background: transparent;
    text-align: left;
    cursor: pointer;
    color: inherit;
    font-family: var(--font-body);
    transition: background var(--transition-fast);
}

.pal-row:hover,
.pal-row.is-active {
    background: var(--surface-2);
    border-left-color: var(--row-tint, var(--accent-orange));
}

.pal-row-ic {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--row-tint, var(--accent-orange)) 16%, var(--surface-3));
    font-size: 0.9rem;
    overflow: hidden;
}

.pal-row-ic img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}

.pal-row-main { flex: 1 1 auto; min-width: 0; }

.pal-row-title {
    font-family: var(--font-display);
    font-size: var(--text-base);
    font-weight: 700;
    line-height: 1.35;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pal-row-title mark {
    background: color-mix(in srgb, var(--accent-orange) 26%, transparent);
    color: var(--text);
    border-radius: 3px;
    padding: 0 1px;
}

.pal-row-sub {
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pal-row-meta {
    font-size: var(--text-xs);
    color: var(--text-faint);
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Inline actions — the point of the whole thing for prompt rows:
   search, run, keep, without ever loading a page. */
.pal-row-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    align-items: center;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.pal-row:hover .pal-row-actions,
.pal-row.is-active .pal-row-actions { opacity: 1; }

.pal-act {
    appearance: none;
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    font-family: var(--font-display);
    padding: 4px 9px;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition-fast), border-color var(--transition-fast),
                background var(--transition-fast);
}

.pal-act:hover {
    color: var(--text);
    border-color: var(--accent-orange);
    background: color-mix(in srgb, var(--accent-orange) 16%, var(--surface-3));
}

.pal-act.is-on {
    color: var(--accent-green);
    border-color: color-mix(in srgb, var(--accent-green) 55%, transparent);
}

/* ── Empty / no-result states ───────────────────────────────── */

.pal-note {
    padding: var(--space-8) var(--space-5);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: 1.6;
}

.pal-note strong { color: var(--text); }

.pal-note-ic {
    display: block;
    font-size: 1.9rem;
    margin-bottom: var(--space-3);
    opacity: 0.5;
}

.pal-jump {
    padding: var(--space-3) var(--space-5) var(--space-4);
}

.pal-jump-label {
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: var(--space-3);
}

.pal-jump-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.pal-jump-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.pal-jump-item:hover {
    color: var(--text);
    border-color: var(--accent-orange);
}

.pal-recent-drop {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
    font-size: var(--text-xs);
    padding: 0 2px;
    margin-left: auto;
}

.pal-recent-drop:hover { color: var(--accent-orange); }

/* ── Footer legend ──────────────────────────────────────────── */

.pal-foot {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-size: var(--text-xs);
    color: var(--text-faint);
    flex-wrap: wrap;
}

.pal-foot-k {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.pal-foot kbd {
    display: inline-block;
    min-width: 17px;
    text-align: center;
    padding: 2px 5px;
    border: 1px solid var(--border-hover);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 0.62rem;
    font-weight: 700;
}

.pal-foot-count { margin-left: auto; }

/* ── Small screens ──────────────────────────────────────────── */

@media (max-width: 600px) {
    .pal-panel {
        top: 0;
        left: 0;
        width: 100vw;
        max-height: 100dvh;
        height: 100dvh;
        border-radius: 0;
        border: 0;
        transform: none;
    }

    .pal-panel.is-open { transform: none; }

    .pal-row-actions { opacity: 1; }
    .pal-foot-k { display: none; }
    .pal-foot-count { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .pal-scrim,
    .pal-panel,
    .pal-row,
    .nav-search { transition: none; }

    .pal-spin { animation-duration: 2s; }
}
