/* ------------------------------------------------------------------
   Color tokens (Light default)
   ------------------------------------------------------------------ */

:root {
    --search-bg: #ffffff;
    --search-fg: #111111;

    --search-muted: rgba(0, 0, 0, 0.75);

    --search-border: rgba(0, 0, 0, 0.12);
    --search-border-soft: rgba(0, 0, 0, 0.08);
    --search-border-strong: rgba(0, 0, 0, 0.20);
    --search-badge-border: rgba(0, 0, 0, 0.15);

    --search-hover: rgba(0, 0, 0, 0.03);

    --search-backdrop: rgba(0, 0, 0, 0.45);
    --search-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);

    --search-input-bg: #ffffff;
    --search-btn-bg: #f7f7f7;

    --search-mark-bg: #fff3a0;
    --search-mark-outline: rgba(255, 200, 0, 0.60);
}

/* ------------------------------------------------------------------
   Dark mode overrides
   - Cover common Docsy/Bootstrap variants:
     * data-theme="dark"
     * td-theme-dark
     * data-bs-theme="dark"
   ------------------------------------------------------------------ */

html[data-theme="dark"],
body[data-theme="dark"],
html.td-theme-dark,
body.td-theme-dark,
html[data-bs-theme="dark"],
body[data-bs-theme="dark"] {
    --search-bg: #0f1115;
    --search-fg: #e8eaf0;

    --search-muted: rgba(232, 234, 240, 0.78);

    --search-border: rgba(232, 234, 240, 0.14);
    --search-border-soft: rgba(232, 234, 240, 0.10);
    --search-border-strong: rgba(232, 234, 240, 0.22);
    --search-badge-border: rgba(232, 234, 240, 0.22);

    --search-hover: rgba(232, 234, 240, 0.06);

    --search-backdrop: rgba(0, 0, 0, 0.62);
    --search-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);

    --search-input-bg: #141823;
    --search-btn-bg: #141823;

    --search-input-bg: rgba(0, 0, 0, 0.05);
    --search-mark-outline: rgba(255, 200, 0, 0.55);
}

/* Optional: fallback to OS preference (useful if theme toggle is absent).
   If you have a theme toggle, keeping this is still fine because the
   selectors above will usually take precedence when present. */
@media (prefers-color-scheme: dark) {
    :root {
        --search-bg: #0f1115;
        --search-fg: #e8eaf0;

        --search-muted: rgba(232, 234, 240, 0.78);

        --search-border: rgba(232, 234, 240, 0.14);
        --search-border-soft: rgba(232, 234, 240, 0.10);
        --search-border-strong: rgba(232, 234, 240, 0.22);
        --search-badge-border: rgba(232, 234, 240, 0.22);

        --search-hover: rgba(232, 234, 240, 0.06);

        --search-backdrop: rgba(0, 0, 0, 0.62);
        --search-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);

        --search-input-bg: #141823;
        --search-btn-bg: #141823;

        --search-mark-bg: rgba(255, 230, 120, 0.35);
        --search-mark-outline: rgba(255, 200, 0, 0.55);
    }
}

/* ------------------------------------------------------------------
   Dialog layout & components
   ------------------------------------------------------------------ */

.search-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: var(--search-backdrop);
    z-index: 9998;
}

.search-dialog {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 4rem 1rem 1rem;
}

.search-dialog[hidden],
.search-dialog-backdrop[hidden] {
    display: none !important;
}

.search-dialog__panel {
    width: min(920px, 100%);
    background: var(--search-bg);
    color: var(--search-fg);
    border-radius: 12px;
    box-shadow: var(--search-shadow);
    overflow: hidden;
}

.search-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--search-border);
}

.search-dialog__title {
    font-weight: 700;
}

.search-dialog__close {
    border: 0;
    background: transparent;
    color: var(--search-fg);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.search-dialog__inputrow {
    display: flex;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--search-border-soft);
}

.search-dialog__input {
    flex: 1;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--search-border-strong);
    border-radius: 10px;
    background: var(--search-input-bg);
    color: var(--search-fg);
}

.search-dialog__input::placeholder {
    color: var(--search-muted);
}

.search-dialog__clear {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--search-border-strong);
    border-radius: 10px;
    background: var(--search-btn-bg);
    color: var(--search-fg);
    cursor: pointer;
}

.search-dialog__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--search-border-soft);
}

.search-filter-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--search-border-strong);
    border-radius: 10px;
    background: var(--search-btn-bg);
    color: var(--search-fg);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.search-filter-btn:hover {
    background: var(--search-hover);
}

.search-filter-btn.active {
    background: var(--search-fg);
    color: var(--search-bg);
    border-color: var(--search-fg);
}

.search-dialog__body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 1rem;
}

@media (min-width: 900px) {
    .search-dialog__body {
        grid-template-columns: 1fr 2fr;
    }
}

.search-dialog__section-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.search-dialog__list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 500px;
    overflow-y: auto;
}

.search-item {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--search-border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--search-fg);
    background: transparent;
}

.search-item:hover {
    background: var(--search-hover);
}

.search-item__title {
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.search-item__meta {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    opacity: .8;
    font-size: .85rem;
    color: var(--search-muted);
}

.search-badge {
    display: inline-block;
    padding: 0.05rem 0.45rem;
    border: 1px solid var(--search-badge-border);
    border-radius: 999px;
    color: var(--search-muted);
}

.search-item__snippet {
    opacity: .85;
    margin-top: 0.25rem;
    color: var(--search-muted);
}

/* Highlight for matched substring */
mark {
    background: var(--search-mark-bg);
    color: inherit;
    padding: 0.05em 0.15em;
    border-radius: 0.2em;
}

html[data-theme="dark"] mark,
body[data-theme="dark"] mark,
html.td-theme-dark mark,
body.td-theme-dark mark,
html[data-bs-theme="dark"] mark,
body[data-bs-theme="dark"] mark {
    background: #ffeb3b;
    color: #000;
}

@media (prefers-color-scheme: dark) {
    mark {
        background: #ffeb3b;
        color: #000;
    }
}

/* ------------------------------------------------------------------
   Trigger input (top & sidebar)
   ------------------------------------------------------------------ */

.search-trigger__input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--search-border-strong);
    border-radius: 10px;
    cursor: pointer;
    background: var(--search-input-bg);
    color: var(--search-fg);
}

.search-trigger__input::placeholder {
    color: var(--search-muted);
}

.search-trigger__input:focus {
    outline: none;
}

.search-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#search-nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#search-nav-controls button {
    background: transparent;
    border: 1px solid rgba(232, 234, 240, 0.22);
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    color: #e8eaf0;
    font-size: 14px;
}

#search-nav-controls button:hover {
    background: var(--search-hover);
}

#search-nav-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#unified-search-count {
    font-weight: 500;
    min-width: 45px;
    text-align: center;
    font-size: 14px;
    color: #e8eaf0;
}
