/* 聊天记录数据库搜索 */
.chat-search-panel {
    display: flex;
    width: min(620px, calc(100vw - 32px));
    max-height: min(760px, 88vh);
    padding: 22px;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(15, 118, 110, 0.12);
    border-radius: 24px;
    color: #172033;
    background:
        radial-gradient(circle at 95% 0%, rgba(45, 212, 191, 0.13), transparent 30%),
        #fff;
    box-shadow: 0 28px 90px rgba(15, 23, 42, 0.22);
}

/* Legacy search markup compatibility; active search uses the panel component above. */
.chat-search-modal {
    width: min(94vw, 470px);
    max-height: 86dvh;
    display: flex;
    flex-direction: column;
    padding: 18px;
    border-radius: 26px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(246, 250, 255, 0.90));
    border: 1px solid rgba(255, 255, 255, 0.82);
    box-shadow: 0 24px 64px rgba(64, 78, 103, 0.24);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
}

.chat-search-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 14px;
}

.chat-search-modal .chat-search-kicker {
    color: #007aff;
    font-size: 11px;
    font-weight: 800;
}

.chat-search-header h3 {
    margin: 2px 0 4px;
    color: #0f172a;
    font-size: 20px;
    font-weight: 900;
}

.chat-search-header p {
    margin: 0;
    color: #64748b;
    font-size: 12px;
}

.chat-search-modal .chat-search-close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 14px;
    background: rgba(241, 245, 249, 0.82);
    color: #475569;
    font-size: 24px;
    line-height: 1;
}

.chat-search-controls {
    display: grid;
    grid-template-columns: 1fr 110px;
    gap: 8px;
    margin-bottom: 10px;
}

.chat-search-input,
.chat-search-select {
    min-height: 44px;
    border-radius: 16px !important;
    border: 1px solid rgba(148, 163, 184, 0.28) !important;
    background: rgba(255, 255, 255, 0.82) !important;
    color: #0f172a !important;
    font-size: 16px !important;
}

.chat-search-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.chat-search-primary,
.chat-search-secondary {
    flex: 1;
    min-height: 44px;
    border: 0;
    border-radius: 16px;
    font-weight: 800;
}

.chat-search-primary {
    background: linear-gradient(135deg, #007aff, #34c759);
    color: #fff;
}

.chat-search-secondary {
    background: rgba(241, 245, 249, 0.92);
    color: #334155;
}

.chat-search-modal .chat-search-results {
    flex: 1;
    min-height: 220px;
    overflow: auto;
    padding: 8px;
    border-radius: 18px;
    background: rgba(248, 250, 252, 0.72);
    border: 1px solid rgba(226, 232, 240, 0.78);
}

.chat-search-modal .chat-search-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 170px;
    color: #94a3b8;
    font-size: 13px;
    text-align: center;
}

.chat-search-modal .chat-search-empty.error {
    color: #ff3b30;
}

.chat-search-summary {
    padding: 4px 6px 10px;
    color: #64748b;
    font-size: 12px;
}

.search-result-item {
    padding: 12px !important;
    margin-bottom: 8px;
    border: 1px solid rgba(226, 232, 240, 0.72) !important;
    border-radius: 16px !important;
    background: rgba(255,255,255,0.84) !important;
    box-shadow: 0 8px 20px rgba(64, 78, 103, 0.07);
}

.search-result-sender {
    color: #007aff !important;
    font-size: 13px !important;
    font-weight: 800 !important;
}

.search-result-content {
    margin-top: 5px;
    color: #0f172a !important;
    font-size: 13px !important;
    line-height: 1.55 !important;
}

.search-result-content mark {
    padding: 0 3px;
    border-radius: 4px;
    background: rgba(255, 204, 0, 0.30);
    color: #92400e;
}

.chat-search-modal .chat-search-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 0 2px;
    color: #64748b;
    font-size: 12px;
}

.chat-search-modal .chat-search-pagination button {
    border: 0;
    border-radius: 12px;
    padding: 6px 12px;
    background: rgba(0, 122, 255, 0.12);
    color: #007aff;
    font-weight: 800;
}

.chat-search-modal .chat-search-pagination button:disabled {
    opacity: 0.45;
}


.chat-search-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.chat-search-kicker {
    display: block;
    margin-bottom: 3px;
    color: #0f766e;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.16em;
}

.chat-search-head h3 {
    margin: 0;
    color: #101828;
    font-size: 22px;
    letter-spacing: -0.02em;
}

.chat-search-close {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    padding: 0;
    place-items: center;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    color: #667085;
    background: rgba(255, 255, 255, 0.84);
    font-size: 22px;
    cursor: pointer;
}

.chat-search-close:hover,
.chat-search-close:focus-visible {
    color: #0f766e;
    border-color: rgba(15, 118, 110, 0.35);
    outline: 3px solid rgba(45, 212, 191, 0.16);
}

.chat-search-hint {
    margin: 8px 0 16px;
    color: #667085;
    font-size: 13px;
    line-height: 1.6;
}

.chat-search-query-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 9px;
}

.chat-search-query-row input,
.chat-search-filters select {
    min-width: 0;
    border: 1px solid #d9e1e8;
    color: #172033;
    background: #fff;
    outline: 0;
}

.chat-search-query-row input {
    height: 48px;
    padding: 0 15px;
    border-radius: 14px;
    font-size: 15px;
}

.chat-search-query-row input:focus,
.chat-search-filters select:focus {
    border-color: #14b8a6;
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.12);
}

.chat-search-query-row button {
    min-width: 92px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #0f766e, #14b8a6);
    box-shadow: 0 10px 22px rgba(15, 118, 110, 0.2);
    font-weight: 800;
    cursor: pointer;
}

.chat-search-query-row button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.chat-search-query-row button.is-secondary {
    min-width: 70px;
    color: #475467;
    border: 1px solid #d9e1e8;
    background: #fff;
    box-shadow: none;
}

.chat-search-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
    margin: 11px 0 13px;
}

.chat-search-filters label {
    display: grid;
    gap: 5px;
}

.chat-search-filters label > span {
    color: #7a8798;
    font-size: 11px;
    font-weight: 750;
}

.chat-search-filters select {
    height: 40px;
    padding: 0 10px;
    border-radius: 12px;
    font-size: 13px;
}

.chat-search-results {
    flex: 1 1 240px;
    min-height: 0;
    overflow: auto;
    border: 1px solid #e8edf2;
    border-radius: 16px;
    background: #f8fafc;
    overscroll-behavior: contain;
}

.chat-search-empty,
.chat-search-loading {
    display: flex;
    min-height: 180px;
    padding: 24px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: #7a8798;
    text-align: center;
    font-size: 13px;
}

.chat-search-empty.is-error {
    color: #b42318;
}

.chat-search-loading > span {
    width: 18px;
    height: 18px;
    border: 2px solid #cbd5e1;
    border-top-color: #0f766e;
    border-radius: 50%;
    animation: chatSearchSpin 700ms linear infinite;
}

.chat-search-result-list {
    display: grid;
    gap: 1px;
    padding: 7px;
}

.chat-search-result {
    display: grid;
    width: 100%;
    gap: 6px;
    padding: 13px 14px;
    border: 0;
    border-radius: 13px;
    color: #253247;
    background: #fff;
    text-align: left;
    cursor: pointer;
}

.chat-search-result:hover,
.chat-search-result:focus-visible {
    outline: 2px solid rgba(20, 184, 166, 0.24);
    background: #f0fdfa;
}

.chat-search-result-meta {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    color: #7a8798;
    font-size: 11px;
}

.chat-search-result-meta strong {
    max-width: 34%;
    overflow: hidden;
    color: #0f766e;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-search-result-meta time {
    margin-left: auto;
    white-space: nowrap;
}

.chat-search-result-text {
    overflow: hidden;
    font-size: 13px;
    line-height: 1.6;
    text-overflow: ellipsis;
}

.chat-search-result-text mark {
    padding: 1px 3px;
    border-radius: 4px;
    color: #7c2d12;
    background: #fef3c7;
}

.chat-search-type {
    margin-right: 6px;
    padding: 2px 6px;
    border-radius: 999px;
    color: #155e75;
    background: #cffafe;
    font-size: 10px;
    font-weight: 800;
}

.chat-search-result-action {
    color: #0f766e;
    font-size: 11px;
    font-weight: 750;
}

.chat-search-pagination {
    display: flex;
    min-height: 48px;
    padding: 8px 12px;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-top: 1px solid #e8edf2;
    color: #667085;
    background: #fff;
    font-size: 11px;
}

.chat-search-pagination button {
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid #d9e1e8;
    border-radius: 10px;
    color: #344054;
    background: #fff;
    cursor: pointer;
}

.chat-search-pagination button:disabled {
    cursor: default;
    opacity: 0.4;
}

.message-search-target {
    animation: messageSearchTarget 2.4s ease;
}

@keyframes chatSearchSpin {
    to { transform: rotate(360deg); }
}

@keyframes messageSearchTarget {
    0%, 100% { filter: none; }
    20%, 75% { filter: drop-shadow(0 0 9px rgba(245, 158, 11, 0.65)); }
}

@media (max-width: 560px) {
    .chat-search-panel {
        width: calc(100vw - 18px);
        max-height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(18px, env(safe-area-inset-bottom)));
        padding: 17px;
        border-radius: 21px;
    }

    .chat-search-head h3 {
        font-size: 19px;
    }

    .chat-search-filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
    }

    .chat-search-query-row button {
        min-width: 76px;
    }

    .chat-search-query-row {
        grid-template-columns: 1fr 1fr;
    }

    .chat-search-query-row input {
        grid-column: 1 / -1;
    }

    .chat-search-query-row button.is-secondary {
        min-width: 60px;
    }

    .chat-search-result-meta {
        flex-wrap: wrap;
    }

    .chat-search-result-meta time {
        width: 100%;
        margin-left: 0;
    }
}
