/* =============================================
   Network Search – Frontend Styles
   ID-scoped to override any theme inheritance
   ============================================= */

/* ── Hard reset on wrapper + ALL descendants ──── */
#ns-search-root {
    all: initial;
    display: block;
    box-sizing: border-box;
    position: relative;
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1e293b;
    z-index: 5;
    -webkit-text-size-adjust: 100%;
}

/* Reset every child element to prevent theme bleed */
#ns-search-root *,
#ns-search-root *::before,
#ns-search-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    font: inherit;
    color: inherit;
    background: transparent;
    text-decoration: none;
    vertical-align: baseline;
    line-height: inherit;
    -webkit-font-smoothing: antialiased;
}

/* Explicit resets for common theme-targeted elements */
#ns-search-root h1,
#ns-search-root h2,
#ns-search-root h3,
#ns-search-root h4,
#ns-search-root h5,
#ns-search-root h6 {
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    margin: 0;
    padding: 0;
    line-height: inherit;
    letter-spacing: normal;
    text-transform: none;
}

#ns-search-root p {
    font-size: inherit;
    color: inherit;
    margin: 0;
    padding: 0;
    line-height: inherit;
}

#ns-search-root a {
    color: inherit;
    text-decoration: none;
    background: transparent;
}

#ns-search-root a:hover,
#ns-search-root a:focus {
    text-decoration: none;
}

#ns-search-root button {
    font-family: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

#ns-search-root input {
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

#ns-search-root svg {
    display: inline-block;
    vertical-align: middle;
}

/* ── Search form ──────────────────────────────── */
#ns-search-root .ns-search-form {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--ns-form-bg, #fff);
    border: 1px solid var(--ns-form-border, #ddd);
    border-radius: var(--ns-form-radius, 12px);
    padding: 8px 8px 8px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: border-color .2s ease, box-shadow .2s ease;
}

#ns-search-root .ns-search-form:focus-within {
    border-color: var(--ns-form-focus, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

/* Icon */
#ns-search-root .ns-search-icon {
    flex-shrink: 0;
    color: #94a3b8;
    display: flex;
    align-items: center;
}

/* Clear button */
#ns-search-root .ns-clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: none;
    color: #94a3b8;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: color .15s ease, background .15s ease;
}
#ns-search-root .ns-clear-btn:hover {
    color: #1e293b;
    background: #f1f5f9;
}

/* Input */
#ns-search-root .ns-search-input {
    flex: 1;
    border: 0 none !important;
    outline: 0 none !important;
    background: transparent !important;
    font-size: 16px;
    line-height: 1.5;
    color: var(--ns-input-color, #1e293b);
    min-width: 0;
    padding: 0 !important;
    margin: 0 !important;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none !important;
}
#ns-search-root .ns-search-input:focus,
#ns-search-root .ns-search-input:active {
    border: 0 none !important;
    outline: 0 none !important;
    box-shadow: none !important;
}
#ns-search-root .ns-search-input::placeholder {
    color: var(--ns-placeholder, #94a3b8);
}

/* Submit button */
#ns-search-root .ns-search-btn {
    flex-shrink: 0;
    background: var(--ns-btn-bg, #3b82f6);
    color: var(--ns-btn-color, #fff);
    border: none;
    border-radius: var(--ns-btn-radius, 8px);
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
#ns-search-root .ns-search-btn:hover {
    background: var(--ns-btn-hover, #2563eb);
    color: var(--ns-btn-hover-color, #fff);
}

/* ── Loading ──────────────────────────────────── */
#ns-search-root .ns-loading {
    display: flex;
    justify-content: center;
    padding: 32px 0;
}
#ns-search-root .ns-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: ns-spin .6s linear infinite;
}
@keyframes ns-spin { to { transform: rotate(360deg); } }

/* ── Results overlay (desktop) ────────────────── */
#ns-search-root .ns-results-area {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--ns-result-bg, #fff);
    border: 1px solid var(--ns-result-border, #e2e8f0);
    border-radius: var(--ns-result-radius, 14px);
    box-shadow: 0 12px 40px rgba(0,0,0,.12);
    max-height: 520px;
    overflow-y: auto;
    z-index: 6;
}

/* Backdrop */
#ns-search-root.ns-overlay-active::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.2);
    z-index: -1;
}

/* ── Results meta ─────────────────────────────── */
#ns-search-root .ns-results-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
    color: #64748b;
}
#ns-search-root .ns-results-count {
    font-weight: 600;
    color: #1e293b;
}

/* ── Result item ──────────────────────────────── */
#ns-search-root .ns-result-item {
    display: flex;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid #f8fafc;
    transition: background .12s ease;
}
#ns-search-root .ns-result-item:last-child {
    border-bottom: none;
}
#ns-search-root .ns-result-item:hover {
    background: var(--ns-result-hover, #f8fafc);
}

#ns-search-root .ns-result-content {
    flex: 1;
    min-width: 0;
}

#ns-search-root .ns-result-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}
#ns-search-root .ns-result-site,
#ns-search-root .ns-result-type {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 2px 8px;
    border-radius: 4px;
}
#ns-search-root .ns-result-site {
    background: var(--ns-site-bg, #eff6ff);
    color: var(--ns-site-color, #3b82f6);
}
#ns-search-root .ns-result-type {
    background: var(--ns-type-bg, #f0fdf4);
    color: var(--ns-type-color, #22c55e);
}

#ns-search-root .ns-result-title {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}
#ns-search-root .ns-result-title a {
    color: var(--ns-result-title, #1e293b);
    text-decoration: none;
}
#ns-search-root .ns-result-title a:hover {
    color: #3b82f6;
}

#ns-search-root .ns-result-excerpt {
    margin: 0 0 6px;
    font-size: 14px;
    color: var(--ns-result-text, #64748b);
    line-height: 1.5;
}

#ns-search-root .ns-result-footer {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: #94a3b8;
}

/* Highlight */
#ns-search-root .ns-highlight {
    background: var(--ns-highlight-bg, #fef9c3);
    color: var(--ns-highlight-color, #92400e);
    padding: 1px 3px;
    border-radius: 2px;
}

/* ── No results ───────────────────────────────── */
#ns-search-root .ns-no-results {
    padding: 40px 20px;
    text-align: center;
    color: #94a3b8;
    font-size: 15px;
}

/* ── Load more ────────────────────────────────── */
#ns-search-root .ns-load-more-wrap {
    padding: 14px 20px;
    text-align: center;
    border-top: 1px solid #f1f5f9;
}
#ns-search-root .ns-load-more {
    background: #f1f5f9;
    color: #475569;
    border: none;
    border-radius: 8px;
    padding: 10px 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease;
}
#ns-search-root .ns-load-more:hover {
    background: #e2e8f0;
}

/* ── Mobile (full-screen overlay) ─────────────── */
@media (max-width: 640px) {
    #ns-search-root.ns-overlay-active {
        position: fixed;
        inset: 0;
        z-index: 99999;
        background: #fff;
        display: flex;
        flex-direction: column;
        padding: 16px;
        max-width: none;
        border-radius: 0;
    }

    #ns-search-root.ns-overlay-active::before {
        display: none;
    }

    #ns-search-root.ns-overlay-active .ns-search-form {
        flex-shrink: 0;
    }

    #ns-search-root.ns-overlay-active .ns-results-area {
        position: relative;
        top: auto;
        margin-top: 12px;
        flex: 1;
        max-height: none;
        overflow-y: auto;
        border-radius: 12px;
    }

    #ns-search-root .ns-result-item {
        flex-direction: column;
        gap: 10px;
        padding: 14px 16px;
    }

    #ns-search-root .ns-result-title {
        font-size: 15px;
    }
}
