/* ノート内検索（Ctrl+Shift+F）。閲覧画面・編集画面で共用。 */

.nf-bar {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 10050;
    width: 480px;
    max-width: 100vw;
    box-sizing: border-box;
    background: #ffffff;
    border: 1px solid #d0d3d8;
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
                 "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    /* キーボード表示時の画面ずれ（スマホ）に追従する */
    transform: translate(var(--nf-dx, 0px), var(--nf-dy, 0px));
}

.nf-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
}

.nf-icon { color: #6b7280; font-size: .95rem; flex: 0 0 auto; }

.nf-input {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px;              /* iOSの自動ズーム防止（16px未満だと拡大される） */
    line-height: 1.4;
    padding: 6px 8px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background: #fff;
    color: #212529;
}
.nf-input:focus { outline: 2px solid #86b7fe; outline-offset: -1px; }

.nf-count {
    flex: 0 0 auto;
    font-size: .8rem;
    color: #6b7280;
    min-width: 56px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.nf-count.nf-none { color: #dc3545; }

.nf-btn {
    flex: 0 0 auto;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background: #f8f9fa;
    color: #333;
    font-size: .9rem;
    line-height: 1;
    cursor: pointer;
}
.nf-btn:hover:not(:disabled) { background: #e9ecef; }
.nf-btn:disabled { opacity: .4; cursor: default; }

/* ヒット一覧（各ヒットにつき5行のプレビュー） */
.nf-list {
    max-height: 58vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 1px solid #e5e7eb;
}
.nf-list[hidden] { display: none; }

.nf-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    border-bottom: 1px solid #f1f3f5;
    border-left: 3px solid transparent;
    background: transparent;
    cursor: pointer;
    font: inherit;
}
.nf-item:hover { background: #f8f9fa; }
.nf-item.nf-cur { background: #fff8e1; border-left-color: #f59e0b; }

.nf-meta {
    font-size: .72rem;
    color: #6b7280;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nf-meta b { color: #374151; font-weight: 600; }

.nf-prev {
    margin: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .78rem;
    line-height: 1.5;
    color: #374151;
    white-space: pre-wrap;
    word-break: break-word;
}
.nf-prev .nf-l1 { color: #111827; }
.nf-prev mark {
    background: #fde68a;
    color: #111827;
    padding: 0 1px;
    border-radius: 2px;
}

.nf-note {
    padding: 10px;
    font-size: .8rem;
    color: #6b7280;
    text-align: center;
}
.nf-note a, .nf-scope-link {
    color: #0d6efd;
    text-decoration: underline;
    cursor: pointer;
    background: none;
    border: none;
    font: inherit;
    padding: 0;
}

/* 本文側のハイライト。Highlight APIが使えない環境では <mark> を挿入する */
::highlight(nf-all) { background-color: #fde68a; color: #111827; }
::highlight(nf-cur) { background-color: #f59e0b; color: #111827; }
mark.nf-hit { background: #fde68a; color: #111827; }
mark.nf-hit.nf-hit-cur { background: #f59e0b; }

/* 編集画面: textarea には色を付けられないので、上に重ねて現在のヒットを示す */
.nf-ta-hl {
    position: absolute;
    pointer-events: none;
    background: rgba(245, 158, 11, .45);
    box-shadow: 0 0 0 1px rgba(245, 158, 11, .9);
    border-radius: 2px;
    z-index: 3;
}

/* 検索を開いた行に一瞬だけ枠を出す（ハイライトが当てられなかった時の代替） */
.nf-flash {
    animation: nf-flash 1.4s ease-out;
    border-radius: 4px;
}
@keyframes nf-flash {
    from { box-shadow: 0 0 0 3px rgba(245, 158, 11, .75); }
    to   { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0); }
}

/* ── スマホ ───────────────────────────────── */
@media (max-width: 768px) {
    .nf-bar { left: 0; right: 0; width: auto; border-radius: 0; }
    .nf-list { max-height: 52vh; }
    .nf-btn { min-width: 44px; height: 44px; font-size: 1rem; }
    .nf-input { padding: 9px 10px; }
    .nf-count { min-width: 48px; }
}

/* ── ダークテーマ ─────────────────────────── */
[data-theme="dark"] .nf-bar { background: #161b22; border-color: #30363d; }
[data-theme="dark"] .nf-input { background: #0d1117; border-color: #30363d; color: #e6edf3; }
[data-theme="dark"] .nf-btn { background: #21262d; border-color: #30363d; color: #e6edf3; }
[data-theme="dark"] .nf-btn:hover:not(:disabled) { background: #30363d; }
[data-theme="dark"] .nf-list { border-top-color: #30363d; }
[data-theme="dark"] .nf-item { border-bottom-color: #21262d; }
[data-theme="dark"] .nf-item:hover { background: #21262d; }
[data-theme="dark"] .nf-item.nf-cur { background: #2d2410; }
[data-theme="dark"] .nf-prev { color: #c9d1d9; }
[data-theme="dark"] .nf-prev .nf-l1 { color: #e6edf3; }
[data-theme="dark"] .nf-meta b { color: #c9d1d9; }

@media print { .nf-bar { display: none !important; } }
