/* ============================================
   Better French — Search Overlay
   Command-palette style: full-screen mobile, centered modal desktop
   Inherits design tokens from index.css (--french-blue, --ease-out, etc.)
   ============================================ */

/* Header trigger button */
.header-search-btn {
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.6);
    transition: background 200ms ease, color 200ms ease;
    outline: none;
}
.header-search-btn:hover { background: rgba(0, 0, 0, 0.05); color: rgba(0, 0, 0, 0.85); }
.header-search-btn:active { background: rgba(0, 0, 0, 0.08); }
.header-search-btn:focus-visible { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4); }

/* Lock body scroll when open */
body.bf-search-open { overflow: hidden; }

/* ── Overlay root ───────────────────────────── */
#bf-search-overlay {
    position: fixed;
    inset: 0;
    /* Above feature-celebration (10001), partner/trial overlays (10001), and confetti (10002) */
    z-index: 10003;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease;
}
#bf-search-overlay[hidden] { display: none; }
#bf-search-overlay.is-open { opacity: 1; pointer-events: auto; }

.bf-search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 12, 20, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* ── Modal container ───────────────────────── */
.bf-search-modal {
    position: relative;
    width: 100%;
    max-width: 680px;
    margin: 10vh 16px 16px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04),
        0 10px 30px rgba(0, 0, 0, 0.12),
        0 30px 60px rgba(0, 0, 0, 0.10);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    overflow: hidden;
    transform: translateY(-12px) scale(0.98);
    transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
    font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #0f172a;
}
#bf-search-overlay.is-open .bf-search-modal { transform: translateY(0) scale(1); }

/* ── Input row ──────────────────────────────── */
.bf-search-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.bf-search-input-icon {
    color: rgba(0, 0, 0, 0.35);
    flex-shrink: 0;
}
.bf-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: 17px;
    font-weight: 500;
    color: #0f172a;
    padding: 8px 0;
    min-width: 0;
    /* Remove default search-input browser styling */
    -webkit-appearance: none;
    appearance: none;
}
.bf-search-input::placeholder { color: rgba(0, 0, 0, 0.35); font-weight: 400; }
.bf-search-input::-webkit-search-decoration,
.bf-search-input::-webkit-search-cancel-button,
.bf-search-input::-webkit-search-results-button,
.bf-search-input::-webkit-search-results-decoration { -webkit-appearance: none; display: none; }

.bf-search-clear {
    background: rgba(0, 0, 0, 0.06);
    border: none;
    border-radius: 999px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(0, 0, 0, 0.5);
    padding: 0;
    flex-shrink: 0;
    transition: background 150ms ease;
}
.bf-search-clear:hover { background: rgba(0, 0, 0, 0.10); color: rgba(0, 0, 0, 0.75); }

.bf-search-close {
    background: transparent;
    border: none;
    color: #2563eb;
    font: inherit;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    padding: 6px 4px;
    flex-shrink: 0;
    border-radius: 6px;
    transition: background 150ms ease;
}
.bf-search-close:hover { background: rgba(37, 99, 235, 0.08); }
.bf-search-close:focus-visible { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4); outline: none; }

/* ── Body (scrollable) ─────────────────────── */
.bf-search-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 20px;
    -webkit-overflow-scrolling: touch;
}

/* ── Empty state (trending) ────────────────── */
.bf-search-empty {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 6px;
}
.bf-search-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.42);
    padding: 0 2px;
}
.bf-trending-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.bf-trending-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    color: #0f172a;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 150ms ease, transform 150ms ease, border-color 150ms ease;
    opacity: 0;
    animation: bf-pill-in 260ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: calc(var(--i, 0) * 24ms);
}
.bf-trending-pill svg { color: rgba(0, 0, 0, 0.4); flex-shrink: 0; }
.bf-trending-pill:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.25);
    transform: translateY(-1px);
}
.bf-trending-pill:hover svg { color: #2563eb; }
.bf-trending-pill:active { transform: translateY(0); }
.bf-trending-pill:focus-visible { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4); outline: none; }
@keyframes bf-pill-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bf-search-hint {
    text-align: center;
    padding: 16px 12px 6px;
}
.bf-search-hint p {
    font-size: 13px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.4);
    margin: 0;
}

/* ── Results list ──────────────────────────── */
.bf-search-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.bf-search-result {
    padding: 12px 14px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
    opacity: 0;
    animation: bf-result-in 240ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: calc(var(--i, 0) * 26ms);
}
.bf-search-result:hover,
.bf-search-result.is-active {
    background: rgba(37, 99, 235, 0.06);
    border-color: rgba(37, 99, 235, 0.25);
}
.bf-search-result:active { transform: scale(0.995); }
@keyframes bf-result-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bf-search-result__title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    color: #0f172a;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.bf-search-result__subtitle {
    margin-top: 3px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.35;
    color: rgba(0, 0, 0, 0.48);
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.bf-search-result__meta {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 12px;
    color: rgba(0, 0, 0, 0.48);
}
.bf-search-result__source { font-weight: 500; }
.bf-search-result__dot { color: rgba(0, 0, 0, 0.25); }
.bf-search-result__time { color: rgba(0, 0, 0, 0.38); }
.bf-search-result__cat {
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
    font-size: 10px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.bf-search-result__highlight {
    background: transparent;
    color: #2563eb;
    font-weight: 700;
}
.bf-search-result__subtitle .bf-search-result__highlight { font-weight: 600; color: rgba(37, 99, 235, 0.75); }

/* ── No results ────────────────────────────── */
.bf-search-no-results {
    text-align: center;
    padding: 40px 20px 30px;
    color: rgba(0, 0, 0, 0.6);
}
.bf-search-no-results svg { color: rgba(0, 0, 0, 0.18); margin-bottom: 10px; }
.bf-search-no-results__title {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 6px;
    word-break: break-word;
}
.bf-search-no-results__subtitle {
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    color: rgba(0, 0, 0, 0.5);
}

/* ── Flash highlight on jumped-to article card ─ */
.article-card.bf-search-flash {
    animation: bf-card-flash 1600ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes bf-card-flash {
    0%   { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.0), 0 0 0 0 rgba(37, 99, 235, 0.0); }
    15%  { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.45), 0 8px 28px rgba(37, 99, 235, 0.18); }
    100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.0), 0 0 0 0 rgba(37, 99, 235, 0.0); }
}

/* ── Mobile: full-screen overlay ───────────── */
@media (max-width: 768px) {
    .bf-search-modal {
        margin: 0;
        max-width: 100%;
        max-height: 100%;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        /* Respect safe-area on notched devices */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    #bf-search-overlay { align-items: stretch; }
    .bf-search-input-row { padding: 12px 14px; }
    .bf-search-input { font-size: 16px; /* prevents iOS zoom on focus */ }
    .bf-search-body { padding: 12px 14px 24px; }
}

/* ── Dark mode ──────────────────────────────── */
@media (prefers-color-scheme: dark) {
    .header-search-btn { color: rgba(255, 255, 255, 0.7); }
    .header-search-btn:hover { background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.95); }
    .header-search-btn:active { background: rgba(255, 255, 255, 0.12); }

    .bf-search-backdrop { background: rgba(0, 0, 0, 0.7); }

    .bf-search-modal {
        background: #121214;
        color: #ffffff;
        box-shadow:
            0 1px 2px rgba(0, 0, 0, 0.4),
            0 10px 30px rgba(0, 0, 0, 0.5),
            0 30px 60px rgba(0, 0, 0, 0.4);
    }
    .bf-search-input-row { border-bottom-color: rgba(255, 255, 255, 0.08); }
    .bf-search-input-icon { color: rgba(255, 255, 255, 0.4); }
    .bf-search-input { color: #ffffff; }
    .bf-search-input::placeholder { color: rgba(255, 255, 255, 0.38); }

    .bf-search-clear { background: rgba(255, 255, 255, 0.10); color: rgba(255, 255, 255, 0.55); }
    .bf-search-clear:hover { background: rgba(255, 255, 255, 0.16); color: rgba(255, 255, 255, 0.85); }

    .bf-search-close { color: #60a5fa; }
    .bf-search-close:hover { background: rgba(96, 165, 250, 0.12); }

    .bf-search-section-label { color: rgba(255, 255, 255, 0.42); }
    .bf-search-hint p { color: rgba(255, 255, 255, 0.4); }

    .bf-trending-pill {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.08);
        color: #ffffff;
    }
    .bf-trending-pill svg { color: rgba(255, 255, 255, 0.4); }
    .bf-trending-pill:hover {
        background: rgba(96, 165, 250, 0.14);
        border-color: rgba(96, 165, 250, 0.4);
    }
    .bf-trending-pill:hover svg { color: #60a5fa; }

    .bf-search-result {
        background: #1a1a1e;
        border-color: rgba(255, 255, 255, 0.08);
    }
    .bf-search-result:hover,
    .bf-search-result.is-active {
        background: rgba(96, 165, 250, 0.10);
        border-color: rgba(96, 165, 250, 0.35);
    }
    .bf-search-result__title { color: #ffffff; }
    .bf-search-result__subtitle { color: rgba(255, 255, 255, 0.5); }
    .bf-search-result__meta { color: rgba(255, 255, 255, 0.5); }
    .bf-search-result__dot { color: rgba(255, 255, 255, 0.3); }
    .bf-search-result__time { color: rgba(255, 255, 255, 0.4); }
    .bf-search-result__cat {
        background: rgba(255, 255, 255, 0.08);
        color: rgba(255, 255, 255, 0.55);
    }
    .bf-search-result__highlight { color: #60a5fa; }
    .bf-search-result__subtitle .bf-search-result__highlight { color: rgba(96, 165, 250, 0.75); }

    .bf-search-no-results__title { color: #ffffff; }
    .bf-search-no-results__subtitle { color: rgba(255, 255, 255, 0.5); }
    .bf-search-no-results svg { color: rgba(255, 255, 255, 0.2); }

    @keyframes bf-card-flash {
        0%   { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.0), 0 0 0 0 rgba(96, 165, 250, 0.0); }
        15%  { box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.5), 0 8px 28px rgba(96, 165, 250, 0.2); }
        100% { box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.0), 0 0 0 0 rgba(96, 165, 250, 0.0); }
    }
}

/* ── Reduced motion ────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #bf-search-overlay,
    .bf-search-modal,
    .bf-trending-pill,
    .bf-search-result,
    .article-card.bf-search-flash {
        transition: none !important;
        animation: none !important;
    }
    #bf-search-overlay.is-open .bf-search-modal { transform: none; }
    .bf-trending-pill,
    .bf-search-result { opacity: 1 !important; }
}
