/*
 * topbar-search.css — single source of truth for the global search bar
 * in base.html. Replaces the messy inline styles + 4 conflicting
 * editorial-overlay rules that fought each other for specificity.
 *
 * Markup contract:
 *   <div class="topbar-search">
 *     <label class="topbar-search-field" for="globalSearchInput">
 *       <i class="bi bi-search topbar-search-icon"></i>
 *       <input id="globalSearchInput" ...>
 *       <kbd class="topbar-search-kbd">Ctrl K</kbd>
 *     </label>
 *     <div id="globalSearchResults" class="topbar-search-results" ...></div>
 *   </div>
 *
 * The <label> wraps the field so click-anywhere focuses the input —
 * fixes the "doesn't work when I click it" bug.
 */

/* Outer container: positions the dropdown and reserves the topbar slot. */
.topbar-search {
    position: relative;
    flex: 1 1 0;
    margin: 0 1rem;
    max-width: 700px;
}

/* The clickable pill. <label for="..."> means clicking ANY pixel here
   focuses the underlying input — even the icon and the kbd chip. */
.topbar-search-field {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 36px;
    padding: 0 8px 0 14px;
    border: 1px solid var(--border-200, var(--border-subtle));
    border-radius: var(--r-md, 10px);
    background: var(--bg-50, var(--surface-1));
    cursor: text;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.topbar-search-field:focus-within {
    /* No yellow halo. Ben's repeated complaint was "yellow border around
       the search bar that isn't flush" — kill the accent-coloured focus
       border, just keep a slightly stronger neutral border so the focus
       state is still visible without any yellow. 2026-05-11. */
    border-color: var(--ink-strong, var(--text-700));
    box-shadow: none;
    outline: none;
}

.topbar-search-icon {
    color: var(--text-400, var(--ink-faint));
    font-size: 0.85rem;
    flex-shrink: 0;
    line-height: 1;
    pointer-events: none;  /* let the <label> capture the click */
}

.topbar-search-field input {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text-900, var(--ink-strong));
    font-size: 0.85rem;
    font-family: inherit;
    padding: 0;
    margin: 0;
    box-shadow: none;
    /* Kill UA "search" widget chrome if a future template uses type=search */
    -webkit-appearance: none;
    appearance: none;
}
.topbar-search-field input::placeholder {
    color: var(--text-400, var(--ink-faint));
    opacity: 1;
}
.topbar-search-field input::-webkit-search-cancel-button { -webkit-appearance: none; }

.topbar-search-kbd {
    flex-shrink: 0;
    font-size: 0.65rem;
    color: var(--ink-muted);
    background: var(--surface-2);
    border: 1px solid var(--border-standard, var(--border-subtle));
    border-radius: var(--r-sm, 4px);
    padding: 2px 6px;
    font-family: var(--font-mono, ui-monospace, monospace);
    pointer-events: none;  /* clicks pass through to <label> */
    line-height: 1.2;
    align-self: center;
    user-select: none;
}

.topbar-search-results {
    position: absolute;
    top: 100%; left: 0; right: 0;
    z-index: 1050;
    background: var(--bg-0, var(--surface-0));
    border: 1px solid var(--border-200, var(--border-subtle));
    border-radius: var(--r-md, 10px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    margin-top: 4px;
    max-height: 500px;
    overflow-y: auto;
    min-width: 400px;
}

/* ── Editorial overrides — single block. Replaces ~4 conflicting blocks
   in editorial-overlay.css that were producing double borders, lost
   focus rings, and a wrapper-vs-input height mismatch. ────────────── */
html[data-design-mode="editorial"] .topbar-search-field {
    background: #fbfaf6 !important;
    border: 1px solid #d9d4c4 !important;
    border-radius: 2px !important;
    height: 34px !important;
}
html[data-design-mode="editorial"] .topbar-search-field:focus-within {
    border-color: #0a0a0a !important;
    box-shadow: none !important;
}
html[data-design-mode="editorial"] .topbar-search-icon {
    color: #5d5d5a !important;
}
html[data-design-mode="editorial"] .topbar-search-field input {
    color: #0a0a0a !important;
    font-family: "Inter", -apple-system, sans-serif !important;
    font-size: 0.82rem !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
}
html[data-design-mode="editorial"] .topbar-search-field input::placeholder {
    color: #8a8a82 !important;
}
html[data-design-mode="editorial"] .topbar-search-kbd {
    background: #ece8da !important;
    color: #5d5d5a !important;
    border: 1px solid #d9d4c4 !important;
    font-family: "JetBrains Mono", ui-monospace, monospace !important;
    font-size: 0.62rem !important;
    border-radius: 2px !important;
}
html[data-design-mode="editorial"] .topbar-search-results {
    background: #fbfaf6 !important;
    border: 1px solid #d9d4c4 !important;
    border-radius: 2px !important;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18) !important;
    color: var(--ink-strong) !important;
}

/* ── Mobile: search hidden by default, opens as a dropdown BELOW the
   topbar with an explicit close button. Round 12 — Ben: "no way to
   click out of the search, want a dropdown that appears below the
   header". Was a full-screen fixed overlay with no close affordance. */
@media (max-width: 767.98px) {
    .topbar-search {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 1100;
        margin: 0;
        padding: 10px 12px;
        background: var(--paper, var(--bg-0, #fbfaf6));
        border-bottom: 1px solid var(--rule, var(--border-100, #d9d4c4));
        box-shadow: 0 8px 20px rgba(0,0,0,0.08);
        max-width: none;
    }
    .topbar-search.is-open {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .topbar-search-field {
        flex: 1;
        height: 40px !important;
        border-radius: 2px !important;
    }
    .topbar-search-kbd {
        display: none;
    }
    .topbar-search-results {
        min-width: 0;
        left: 12px;
        right: 12px;
        top: calc(100% + 4px);
    }
    /* Close button — sits to the right of the search field inside the
       open overlay. Tapping it sets .topbar-search.is-open off. */
    .topbar-search-close {
        flex: 0 0 auto;
        width: 36px;
        height: 36px;
        border: 1px solid var(--rule, var(--border-100, #d9d4c4));
        border-radius: 2px;
        background: var(--paper-2, var(--bg-100));
        color: var(--ink, var(--ink-strong));
        font-size: 1rem;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }
    .topbar-search-close:hover,
    .topbar-search-close:active {
        background: var(--paper-3, var(--bg-200));
    }
}
/* On desktop the close button is hidden — search is always inline */
.topbar-search-close { display: none; }

/* Tap-to-expand trigger button — only rendered/visible on mobile.
   Sits next to the design-mode toggle in `.topbar-actions`.
   Made more visually prominent 2026-05-11 — Ben round 6: "search function
   is not working" likely meant the trigger was hard to spot. Now: solid
   subtle background + visible border so the affordance reads as a real
   button at a glance instead of a stealth icon. */
.topbar-search-trigger {
    display: none;
    width: 38px; height: 38px;
    padding: 0;
    background: var(--bg-100, var(--paper-2, #f4f1e8));
    border: 1px solid var(--border-100, var(--rule, #d9d4c4));
    border-radius: var(--r-md, 8px);
    color: var(--text-700, var(--ink, #0a0a0a));
    font-size: 1.05rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    flex-shrink: 0;
}
.topbar-search-trigger:hover,
.topbar-search-trigger:active {
    background: var(--bg-200, var(--paper-3, #ece8da));
    border-color: var(--ink-3, var(--ink-muted));
}
@media (max-width: 767.98px) {
    .topbar-search-trigger { display: inline-flex; }
}
