/* 搜索模态框紧凑版本 */
.search-modal {
    position: fixed;
    top: 60px;
    right: 20px;
    transform: translateY(-10px) scale(0.95);
    z-index: 10000;
    display: none;
    opacity: 0;
    transition: all 0.2s ease;
    width: 90%;
    max-width: 500px;
}

.search-modal.active {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.search-modal .modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem;
    width: 100%;
    max-height: 70vh;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

/* 搜索头部 */
.search-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    width: 100%;
    position: relative;
}

.search-icon {
    color: var(--primary-color);
    font-size: 0.9rem;
    flex-shrink: 0;
    position: absolute;
    left: 0.75rem;
    z-index: 2;
    top: 50%;
    transform: translateY(-50%);
}

.search-input {
    flex: 1;
    border: 1px solid var(--border-color);
    outline: none;
    font-size: 0.875rem;
    padding: 0.625rem 0.75rem 0.625rem 2.25rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 100%;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.1);
}

.search-input::placeholder {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.875rem;
}

/* 引擎选择器 */
.engine-selector {
    display: flex;
    gap: 0.375rem;
    padding: 0.5rem 0;
    overflow-x: auto;
    scrollbar-width: none;
    justify-content: flex-start;
    flex-wrap: nowrap;
    align-items: center;
    position: relative;
    scroll-behavior: smooth;
    margin: 0.5rem 0;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.engine-selector::-webkit-scrollbar {
    display: none;
}

.engine-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    padding: 0;
    position: relative;
    overflow: hidden;
}

.engine-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(67, 97, 238, 0.15);
}

.engine-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.engine-btn.active i {
    color: white;
}

.engine-btn i {
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.engine-btn img {
    width: 55%;
    height: 55%;
    object-fit: contain;
    border-radius: 3px;
}

/* 工具栏 */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem;
    margin-top: 0.5rem;
}

.toolbar-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-weight: 500;
}

.toolbar-btn:hover {
    color: var(--primary-color);
    background: rgba(67, 97, 238, 0.08);
}

.toolbar-btn.active {
    color: var(--primary-color);
    background: rgba(67, 97, 238, 0.12);
}

/* 设置和历史面板 */
.settings-panel,
.history-panel {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-top: 0.5rem;
    padding: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: none;
    z-index: 1;
    animation: slideDown 0.2s ease-out;
}

.settings-panel.active,
.history-panel.active {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 历史项和建议项 */
.history-item,
.suggestion-item {
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    margin-bottom: 0.25rem;
}

.history-item:hover,
.suggestion-item:hover {
    background: var(--bg-primary);
    transform: translateX(3px);
}

.history-item:last-child {
    margin-bottom: 0;
}

.delete-history {
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0.25rem;
    border-radius: 4px;
    opacity: 0.6;
    font-size: 0.75rem;
}

.delete-history:hover {
    color: var(--error-color);
    background: rgba(239, 68, 68, 0.1);
    opacity: 1;
}

/* 自定义搜索引擎表单 */
.custom-engine-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.custom-engine-form input {
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.8rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    outline: none;
}

.custom-engine-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.1);
}

.custom-engine-form button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.625rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    font-weight: 600;
}

.custom-engine-form button:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
}

/* 搜索建议 */
.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    display: none;
    max-height: 10rem;
    overflow-y: auto;
    z-index: 10001;
    margin-top: 0.25rem;
    backdrop-filter: blur(10px);
}

.suggestions.active {
    display: block;
    animation: slideDown 0.15s ease-out;
}

/* 名称提示工具 */
.engine-tooltip {
    position: fixed;
    background: var(--text-primary);
    color: var(--bg-card);
    padding: 0.375rem 0.625rem;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10002;
    transform: translate(-50%, -100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.engine-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 0.3rem solid transparent;
    border-top-color: var(--text-primary);
}

.engine-tooltip.visible {
    opacity: 1;
}

.engine-tooltip.below {
    transform: translate(-50%, 0);
}

.engine-tooltip.below::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--text-primary);
}

.engine-tooltip.right {
    transform: translate(0, -50%);
}

.engine-tooltip.right::after {
    top: 50%;
    left: -0.6rem;
    transform: translateY(-50%);
    border-top-color: transparent;
    border-right-color: var(--text-primary);
}

/* 移动端优化 */
@media (max-width: 768px) {
    .search-modal {
        position: fixed;
        top: 60px;
        left: 50%;
        right: auto;
        transform: translateX(-50%) scale(0.9);
        width: 92%;
        max-width: 380px;
    }
    
    .search-modal.active {
        transform: translateX(-50%) scale(1);
    }
    
    .search-modal .modal-content {
        padding: 0.875rem;
        max-height: 60vh;
        border-radius: 12px;
    }
    
    .search-header {
        margin-bottom: 0.5rem;
    }
    
    .engine-selector {
        gap: 0.25rem;
        padding: 0.375rem 0;
        margin: 0.375rem 0;
    }
    
    .engine-btn {
        width: 1.75rem;
        height: 1.75rem;
    }
    
    .engine-btn i {
        font-size: 0.8rem;
    }
    
    .search-input {
        font-size: 16px;
        padding: 0.75rem 0.75rem 0.75rem 2.5rem;
    }
    
    .search-icon {
        left: 0.875rem;
        font-size: 0.85rem;
    }
    
    .toolbar-btn {
        padding: 0.375rem 0.625rem;
        font-size: 0.7rem;
        gap: 0.25rem;
    }
    
    .suggestions {
        max-height: 8rem;
    }
    
    .engine-selector {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    
    .engine-btn {
        scroll-snap-align: start;
    }
}

@media (max-width: 480px) {
    .search-modal {
        width: 94%;
        max-width: 340px;
    }
    
    .search-modal .modal-content {
        padding: 0.75rem;
        border-radius: 10px;
        max-height: 55vh;
    }
    
    .search-header {
        margin-bottom: 0.5rem;
    }
    
    .engine-selector {
        padding: 0.25rem 0;
        margin: 0.25rem 0;
    }
    
    .engine-btn {
        width: 1.5rem;
        height: 1.5rem;
    }
    
    .engine-btn i {
        font-size: 0.7rem;
    }
    
    .toolbar {
        padding-top: 0.375rem;
        margin-top: 0.375rem;
    }
    
    .toolbar-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.65rem;
    }
    
    .settings-panel,
    .history-panel {
        padding: 0.625rem;
        margin-top: 0.375rem;
    }
    
    .history-item,
    .suggestion-item {
        padding: 0.375rem;
        font-size: 0.75rem;
    }
    
    .custom-engine-form input {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    .custom-engine-form button {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .search-modal {
        max-width: 450px;
        right: 30px;
    }
}

@media (min-width: 1200px) {
    .search-modal {
        max-width: 500px;
        right: 40px;
    }
}

.history-panel:not(.active),
.settings-panel:not(.active) {
    display: none !important;
}

.history-panel.active,
.settings-panel.active {
    display: block !important;
}

.search-input::-webkit-input-placeholder {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.search-input:-moz-placeholder {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.search-input::-moz-placeholder {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.search-input:-ms-input-placeholder {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.engine-selector {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.engine-selector::-webkit-scrollbar {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    .engine-btn {
        min-width: 2.5rem;
    }
    
    .engine-selector {
        gap: 0.5rem;
    }
}