/* Search uses the same brand palette and floating-navigation spacing as the V2 pages. */
.search-page {
    --search-bg: var(--brand-bg, #F6FBFF);
    --search-surface: #FFFFFF;
    --search-ink: var(--brand-charcoal, #222222);
    --search-muted: #64748B;
    --search-border: var(--brand-divider, #E0E0E0);
    --search-accent: var(--brand-secondary, #0174B1);
    --search-on-accent: #FFFFFF;
    --search-tint: #E6F7FF;
    --search-shadow: 0 2px 6px rgb(15 23 42 / 5%);
    min-height: 70vh;
    padding: calc(120px + var(--topnav-inset-top, 0px)) 24px 64px;
    background: var(--search-bg);
    color: var(--search-ink);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}
body.dark-mode .search-page, html.dark-mode .search-page {
    --search-bg: #0F1620;
    --search-surface: #1B2330;
    --search-ink: #F1F5F9;
    --search-muted: #CBD3DC;
    --search-border: #2E3A4A;
    --search-accent: #00B4FF;
    --search-on-accent: #0F1620;
    --search-tint: #12374B;
    --search-shadow: 0 2px 6px rgb(0 0 0 / 12%);
}
.search-page *, .search-page *::before, .search-page *::after { box-sizing: border-box; }
.search-container { max-width: 1040px; margin: 0 auto; }
.search-header h1 {
    margin: 0;
    color: var(--search-ink);
    font-size: 32px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.03em;
}
.search-header p { margin: 8px 0 18px; color: var(--search-muted); font-size: 16px; line-height: 1.5; }
.search-page button, .search-page input, .search-page select { font: inherit; }
.search-page button { cursor: pointer; }
.search-page button:disabled { cursor: wait; opacity: .65; }
.search-page svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.search-page :is(button, select, a):focus-visible { outline: 3px solid var(--search-accent); outline-offset: 3px; }
.search-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}
.search-form {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 56px;
    padding: 5px 7px 5px 18px;
    border: 1px solid var(--search-border);
    border-radius: 16px;
    background: var(--search-surface);
    box-shadow: var(--search-shadow);
}
.search-form:focus-within { border-color: var(--search-accent); outline: 2px solid var(--search-accent); outline-offset: 2px; }
.search-input-icon { width: 22px; height: 22px; flex: 0 0 auto; color: var(--search-muted); }
.search-form input {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 100%;
    padding: 0 6px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--search-ink);
    font-size: 18px;
    border-radius: 4px;
}
.search-form input::placeholder { color: var(--search-muted); opacity: 1; }
.search-form input:focus { outline: none; box-shadow: none; }
.search-form input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 0;
    border-radius: 10px;
    color: var(--search-muted);
    background: transparent;
}
.search-clear:hover { background: var(--search-tint); color: var(--search-accent); }
.search-clear svg { width: 20px; height: 20px; }
.search-submit {
    min-height: 44px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--search-on-accent);
    background: var(--search-accent);
    font-weight: 600 !important;
    font-size: 14px !important;
    white-space: nowrap;
}
.search-submit:hover { filter: brightness(.95); }
.search-types {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: fit-content;
    max-width: 100%;
    padding: 4px;
    margin: 16px 0 12px;
    border: 1px solid var(--search-border);
    border-radius: 12px;
    background: var(--search-surface);
}
.search-type {
    min-height: 44px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--search-ink);
    font-size: 14px !important;
    font-weight: 500 !important;
}
.search-type:hover { background: var(--search-tint); }
.search-type[aria-pressed="true"] { background: var(--search-accent); color: var(--search-on-accent); font-weight: 700 !important; }
.search-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 20px; }
.search-desktop-filters, .search-filter-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.search-filter-field {
    display: flex;
    position: relative;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    margin: 0;
    padding: 0 12px;
    border: 1px solid var(--search-border);
    border-radius: 10px;
    background: var(--search-surface);
    color: var(--search-ink);
    font-size: 13px;
}
.search-filter-field > span { color: var(--search-muted); white-space: nowrap; font-size: 12px; }
.search-filter-field select {
    min-width: 0;
    max-width: 220px;
    min-height: 42px;
    padding: 8px 22px 8px 0;
    border: 0;
    border-radius: 4px;
    appearance: none;
    background: var(--search-surface);
    color: var(--search-ink);
    font-size: 13px;
    cursor: pointer;
}
.search-filter-field > svg { position: absolute; right: 10px; width: 16px; height: 16px; pointer-events: none; }
.search-filter-active { border-color: var(--search-accent); }
.search-reset { min-height: 44px; padding: 8px; border: 0; background: transparent; color: var(--search-accent); font-size: 13px !important; text-decoration: underline; text-underline-offset: 3px; }
.search-filter-toggle { display: none; }
.search-summary { margin: 0; color: var(--search-muted); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.search-results-list, .search-skeletons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 0; margin: 0; list-style: none; }
.search-results-list > li { min-width: 0; }
.search-result-card {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 100%;
    min-height: 128px;
    padding: 16px;
    border: 1px solid var(--search-border);
    border-radius: 16px;
    background: var(--search-surface);
    color: var(--search-ink);
    text-decoration: none;
    box-shadow: var(--search-shadow);
    transition: border-color .15s, transform .15s;
}
.search-result-card:hover { color: var(--search-ink); text-decoration: none; border-color: var(--search-accent); transform: translateY(-2px); }
.search-result-visual { position: relative; display: flex; align-items: center; justify-content: center; width: 64px; flex: 0 0 64px; min-height: 96px; }
.search-result-visual img { display: block; width: 64px; height: 96px; object-fit: contain; border-radius: 4px; }
.search-result-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.search-result-type { color: var(--search-muted); font-size: 11px; font-weight: 600; line-height: 1.2; letter-spacing: .07em; text-transform: uppercase; }
.search-result-title { color: var(--search-ink); font-size: 15px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.search-result-subtitle { color: var(--search-muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.search-initials, .search-result-placeholder { display: flex; align-items: center; justify-content: center; width: 64px; height: 96px; border-radius: 6px; background: var(--search-tint); color: var(--search-accent); }
.search-result-placeholder svg { width: 28px; height: 28px; }
:is(.search-kind-author, .search-kind-user) .search-result-visual { min-height: 64px; }
:is(.search-kind-author, .search-kind-user) :is(.search-initials, .search-result-visual img) { height: 64px; border-radius: 50%; }
.search-initials { font-size: 20px; font-weight: 600; }
.search-kind-post .search-result-visual img { width: 48px; height: 72px; }
.search-post-mark { position: absolute; right: 0; bottom: 4px; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: var(--search-tint); color: var(--search-accent); border: 2px solid var(--search-surface); border-radius: 50%; }
.search-post-mark svg { width: 16px; height: 16px; }
.search-results-books { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 20px 16px; }
.search-results-books .search-result-card { flex-direction: column; align-items: stretch; gap: 10px; padding: 0; min-height: 0; border: 0; border-radius: 6px; background: transparent; box-shadow: none; }
.search-results-books .search-result-visual { width: 100%; aspect-ratio: 2 / 3; min-height: 0; flex: none; }
.search-results-books :is(.search-result-visual img, .search-result-placeholder) { width: 100%; height: 100%; }
.search-results-books .search-result-title { font-size: 14px; }
.search-results-books .search-result-info { gap: 4px; }
.search-load-more { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 28px; }
.search-load-error { margin: 0; color: var(--search-muted); font-size: 14px; text-align: center; }
.search-action { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border: 1px solid var(--search-border); border-radius: 10px; background: var(--search-surface); color: var(--search-ink); font-size: 14px !important; font-weight: 600 !important; }
.search-action:hover { border-color: var(--search-accent); color: var(--search-accent); }
.search-hint { margin: 28px 0; color: var(--search-muted); font-size: 14px; line-height: 1.6; }
.search-state { padding: 36px 16px; text-align: center; }
.search-state h2 { margin: 12px 0 8px; color: var(--search-ink); font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.search-state p { margin: 0 0 20px; color: var(--search-muted); font-size: 15px; line-height: 1.6; }
.search-state-icon { width: 36px; height: 36px; color: var(--search-muted); }
.search-state-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.search-skeleton { display: flex; align-items: center; gap: 16px; min-height: 128px; padding: 16px; border: 1px solid var(--search-border); border-radius: 16px; background: var(--search-surface); }
.search-skeleton-cover { display: block; width: 64px; height: 96px; flex: 0 0 64px; border-radius: 4px; background: var(--search-border); }
.search-skeleton-lines { display: flex; flex: 1; flex-direction: column; gap: 10px; }
.search-skeleton-lines span { height: 10px; border-radius: 4px; background: var(--search-border); }
.search-skeleton-lines span:first-child { width: 40%; }
.search-skeleton-lines span:last-child { width: 70%; }
.search-skeleton { animation: search-pulse 1.2s ease-in-out infinite alternate; }
.search-spinner { width: 16px; height: 16px; border: 2px solid var(--search-border); border-top-color: var(--search-accent); border-radius: 50%; animation: search-spin .8s linear infinite; }
/* A native modal keeps focus inside the sheet and restores it to its opener on close. */
.search-filter-dialog { color: var(--search-ink); background: var(--search-surface); border: 1px solid var(--search-border); border-radius: 20px; padding: 24px; width: min(480px, calc(100% - 32px)); max-height: 85dvh; }
.search-filter-dialog:not([open]) { display: none; }
.search-filter-dialog[open] { display: flex; flex-direction: column; gap: 24px; }
.search-filter-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.search-sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.search-sheet-header h2 { margin: 0; color: var(--search-ink); font-size: 20px; font-weight: 700; }
.search-filter-dialog .search-filter-controls { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
.search-filter-dialog .search-filter-field { flex-direction: column; align-items: stretch; gap: 0; padding: 10px 12px 0; }
.search-filter-dialog .search-filter-field > span { font-size: 13px; }
.search-filter-dialog .search-filter-field select { width: 100%; max-width: none; font-size: 16px; }
.search-filter-dialog .search-filter-field > svg { top: 39px; }
.search-sheet-actions { display: flex; justify-content: space-between; gap: 12px; }
.search-sheet-actions .search-submit { flex: 1; }
body:has(.search-filter-dialog[open]) { overflow: hidden; }
@keyframes search-pulse { to { opacity: .45; } }
@keyframes search-spin { to { transform: rotate(360deg); } }
@media (max-width: 1000px) {
    .search-results-list, .search-skeletons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .search-results-books { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
    .search-page { padding: calc(104px + var(--topnav-inset-top, 0px)) 20px 48px; }
    .search-header h1 { font-size: 26px; }
    .search-header p { font-size: 15px; margin-bottom: 16px; }
    .search-form { height: 52px; padding-left: 14px; border-radius: 14px; gap: 4px; }
    .search-form input { font-size: 16px; }
    .search-form .search-submit { display: none; }
    .search-types { border: 0; padding: 0; background: transparent; gap: 8px; margin: 16px 0 12px; }
    .search-type { min-height: 44px; border-color: var(--search-border); border-radius: 999px; padding: 8px 16px; background: var(--search-surface); }
    .search-toolbar { gap: 10px; margin-bottom: 20px; }
    .search-desktop-filters { display: none; }
    .search-inline-filters .search-desktop-filters { display: flex; width: 100%; }
    .search-inline-filters .search-filter-controls { width: 100%; }
    .search-inline-filters .search-filter-field { width: 100%; }
    .search-inline-filters .search-filter-field select { flex: 1; max-width: none; }
    .search-inline-filters .search-filter-toggle { display: none; }
    .search-filter-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 9px 12px; border: 1px solid var(--search-border); border-radius: 10px; color: var(--search-ink); background: var(--search-surface); font-size: 13px !important; }
    .search-filter-toggle > svg { width: 18px; height: 18px; }
    .search-filter-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 50%; background: var(--search-accent); color: var(--search-on-accent); font-size: 11px; font-weight: 700; }
    .search-summary { font-size: 12px; }
    .search-results-list, .search-skeletons { grid-template-columns: minmax(0, 1fr); }
    .search-results-books { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 16px; }
    .search-result-card { padding: 16px; }
    .search-filter-dialog { position: fixed; inset: auto 0 0; width: 100%; max-width: 100%; margin: 0; padding: 20px 20px max(20px, env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; border-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .search-result-card { transition: none; }
    .search-result-card:hover { transform: none; }
    .search-skeleton, .search-spinner { animation: none; }
}
